syntax = "proto3";

package ark.v1;

/* Types */

message Outpoint {
  string txid = 1;
  uint32 vout = 2;
}

message Input {
  Outpoint outpoint = 1;
  Tapscripts taproot_tree = 2;
}

message Vtxo {
  Outpoint outpoint = 1;
  uint64 amount = 2;
  string script = 3;
  int64 created_at = 4;
  int64 expires_at = 5;
  repeated string commitment_txids = 6;
  bool is_preconfirmed = 7;
  bool is_swept = 8;
  bool is_unrolled = 9;
  bool is_spent = 10;
  string spent_by = 11;
  string settled_by = 12;
  string ark_txid = 13;
  repeated Asset assets = 14;
}

message Asset {
  string asset_id = 1;
  uint64 amount = 2;
}

message TxData {
  string txid = 1;
  string tx = 2;
}

message TxNotification {
  string txid = 1;
  string tx = 2;
  repeated Vtxo spent_vtxos = 3;
  repeated Vtxo spendable_vtxos = 4;
  // This field is set only in case of offchain tx.
  map<string, TxData> checkpoint_txs = 5; // key: outpoint, value: checkpoint txid
  repeated Outpoint swept_vtxos = 6;
}

message Tapscripts {
  repeated string scripts = 1;
}

message Intent {
  string proof = 1;
  string message = 2;
}

message ScheduledSession {
  int64 next_start_time = 1;
  int64 next_end_time = 2;
  int64 period = 3;
  int64 duration = 4;
  FeeInfo fees = 5;
}

message FeeInfo {
  IntentFeeInfo intent_fee = 1;
  string tx_fee_rate = 2;
}

message IntentFeeInfo  {
  string offchain_input = 1;
  string offchain_output = 2;
  string onchain_input = 3;
  string onchain_output = 4;
}

message PendingTx {
  string ark_txid = 1;
  string final_ark_tx = 2;
  repeated string signed_checkpoint_txs = 3;
}

message DeprecatedSigner {
  string pubkey = 1;
  int64 cutoff_date = 2;
}

/* Events */

message BatchStartedEvent {
  string id = 1;
  repeated string intent_id_hashes = 2;
  int64 batch_expiry = 3;
}

message BatchFinalizationEvent {
  string id = 1;
  string commitment_tx = 2;
}

message BatchFinalizedEvent {
  string id = 1;
  string commitment_txid = 2;
}

message BatchFailedEvent {
  string id = 1;
  string reason = 2;
}

message TreeSigningStartedEvent {
  string id = 1;
  repeated string cosigners_pubkeys = 2;
  string unsigned_commitment_tx = 3;
}

message TreeNoncesAggregatedEvent {
  string id = 1;
  map<string,string> tree_nonces = 2;
}

message TreeNoncesEvent {
  string id = 1;
  repeated string topic = 2;
  string txid = 3;
  map<string, string> nonces = 4; // pubkey -> musig2 public nonce
}

message TreeTxEvent {
  string id = 1;
  repeated string topic = 2;
  int32 batch_index = 3;
  string txid = 4;
  string tx = 5;
  map<uint32, string> children = 6; // output index -> child txid
}

message TreeSignatureEvent {
  string id = 1;
  repeated string topic = 2;
  int32 batch_index = 3;
  string txid = 4;
  string signature = 5;
}

message Heartbeat {
}

message StreamStartedEvent {
  string id = 1;
}


message ErrorDetails {
  int32 code = 1;
  string name = 2;
  string message = 3;
  map<string, string> metadata = 4;
}