syntax = "proto3";

package exchain.nebula.v1;

import "google/protobuf/descriptor.proto";
import "nebula/ext/options.proto";
import "nebula/v1/coin.proto";
import "nebula/v1/order.proto";
import "nebula/v1/pair.proto";

option csharp_namespace = "ExChain.Nebula.V1";
option go_package = "github.com/exchain/go-exchain/exchain/protocol/nebula/v1";
option java_multiple_files = true;
option java_outer_classname = "TransactionProto";
option java_package = "org.exchain.nebula.v1";
option php_namespace = "ExChain\\Nebula\\v1";

enum TxType {
  SignProxyTx = 0;
  DepositTx = 1;
  WithdrawTx = 2;
  CreatePairTx = 3;
  DisablePairTx = 4;
  LimitTx = 5;
  MarketTx = 6;
  CancelTx = 7;
  ProtocolTx = 8;
}

message Signature {
  bytes r = 1;
  bytes s = 2;
  int32 v = 3;
}

message TransactionList {
  repeated Transaction txs = 1;
}

message Transaction {
  TxType tx_type = 1;
  string user = 2;
  bytes nonce = 3;
  bool proxy = 4;
  oneof tx {
    SignProxyTransaction sign_proxy_tx = 5;
    DepositTransaction deposit_tx = 6;
    WithdrawTransaction withdraw_tx = 7;
    CreatePairTransaction create_pair_tx = 8;
    DisablePairTransaction disable_pair_tx = 9;
    LimitOrderTransaction limit_tx = 10;
    MarketOrderTransaction market_tx = 11;
    CancelOrderTransaction cancel_tx = 12;
    ProtocolTransaction protocol_tx = 13;
  }
  Signature signature = 14;
}

message SignProxyTransaction {
  bytes signer_proxy = 1;
}

message DepositTransaction {
  bytes source_hash = 1; // layer1 tx hash.
  bytes user = 2;
  bytes coin = 3;
  bytes amount = 4;
}

message WithdrawTransaction {
  bytes user = 1;
  string coin = 2;
  bytes amount = 3;
}

message CreatePairTransaction {
  Coin base_coin = 1;
  Coin quote_coin = 2;
  PairParam pair_info = 3;
}

message DisablePairTransaction {
  string pair_name = 1;
}

message LimitOrderTransaction {
  string pair = 1;
  OrderSide side = 2;
  bytes price = 3;
  bytes quantity = 4;
}

message MarketOrderTransaction {
  string pair = 1;
  OrderSide side = 2;
  bytes quantity = 3;
}

message CancelOrderTransaction {
  string order_id = 1;
}

message ProtocolTransaction {
  uint64 l1_number = 1;
  uint64 l1_time = 2;
  bytes l1_block_hash = 3;
  uint64 sequence_number = 4;
  bytes batcher_addr = 5;
}
