syntax = "proto3";

package ark.v1;

import "google/api/annotations.proto";

service ArkService {
  rpc RegisterPayment(RegisterPaymentRequest) returns (RegisterPaymentResponse) {
    option (google.api.http) = {
      post: "/v1/payment/register"
      body: "*"
    };
  };
  rpc ClaimPayment(ClaimPaymentRequest) returns (ClaimPaymentResponse) {
    option (google.api.http) = {
      post: "/v1/payment/claim"
      body: "*"
    };
  };
  rpc FinalizePayment(FinalizePaymentRequest) returns (FinalizePaymentResponse) {
    option (google.api.http) = {
      post: "/v1/payment/finalize"
      body: "*"
    };
  };
  rpc GetRound(GetRoundRequest) returns (GetRoundResponse) {
    option (google.api.http) = {
      get: "/v1/round/{txid}"
    };
  };
  rpc GetEventStream(GetEventStreamRequest) returns (stream GetEventStreamResponse) {
    option (google.api.http) = {
      get: "/v1/events"
    };
  };
  rpc Ping(PingRequest) returns (PingResponse) {
    option (google.api.http) = {
      get: "/v1/ping/{payment_id}"
    };
  };
  rpc Faucet(FaucetRequest) returns (FaucetResponse) {
    option (google.api.http) = {
      post: "/v1/faucet/{address}"
    };
  }
  rpc ListVtxos(ListVtxosRequest) returns (ListVtxosResponse) {
    option (google.api.http) = {
      get: "/v1/vtxos/{address}"
    };
  }
  rpc GetPubkey(GetPubkeyRequest) returns (GetPubkeyResponse) {
    option (google.api.http) = {
      get: "/v1/pubkey"
    };
  }
}

message RegisterPaymentRequest {
  repeated Input inputs = 1;
}
message RegisterPaymentResponse {
  // Mocks wabisabi's credentials.
  string id = 1;
}

message ClaimPaymentRequest {
  // Mocks wabisabi's credentials.
  string id = 1;
  // List of receivers for a registered payment. 
  repeated Output outputs = 2;
}
message ClaimPaymentResponse {}

message FinalizePaymentRequest {
  // Forfeit txs signed by the user. 
  repeated string signed_forfeit_txs = 1;
}
message FinalizePaymentResponse {}

message GetRoundRequest {
  string txid = 1;
}
message GetRoundResponse {
  Round round = 1;
}

message Round {
  string id = 1;
  int64 start = 2;
  int64 end = 3;
  string txid = 4;
  Tree congestion_tree = 5;
}

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

message Output {
  string pubkey = 1;
  uint64 amount = 2;
}

message RoundFinalizationEvent {
  string id = 1;
  string pool_partial_tx = 2;
  repeated string forfeit_txs = 3;
  Tree congestion_tree = 4;
}

message Tree {
  repeated TreeLevel levels = 1;
}

message TreeLevel {
  repeated Node nodes = 1;
}

message Node {
  string txid = 1;
  string tx = 2;
  string parent_txid = 3;
}

message RoundFinalizedEvent {
  string id = 1;
  string pool_txid = 2;
}

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

message GetEventStreamRequest {}

message GetEventStreamResponse {
  oneof event {
    RoundFinalizationEvent round_finalization = 1;
    RoundFinalizedEvent round_finalized = 2;
    RoundFailed round_failed = 3;
  }
}

message PingRequest {
  string payment_id = 1;
}

message PingResponse {}

message FaucetRequest {
  string address = 1;
}

message FaucetResponse {}

message ListVtxosRequest {
  string address = 1;
}

message ListVtxosResponse {
  repeated Vtxo vtxos = 1;
}

message Vtxo {
  Input outpoint = 1;
  Output receiver = 2;
  bool spent = 3;
}

message GetPubkeyRequest {}

message GetPubkeyResponse {
  string pubkey = 1;
}