// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

syntax = "proto3";

import "transaction.proto";
import "block.proto";

package tari.base_node;

// Request message used to initiate a sync
message SyncBlocksRequest {
  // Start sending from this hash (exclusive)
  bytes start_hash = 1;
  // The hash of the last block that should be synced
  bytes end_hash = 2;
}

// Response that contains the full body of a block
message BlockBodyResponse {
  bytes hash = 1;
  tari.types.AggregateBody body = 2;
}

// Request message used to initiate a sync
message SyncHeadersRequest {
  // Start sending from this hash (exclusive)
  bytes start_hash = 1;
  // Number of blocks to send. If this is zero (empty) the peer SHOULD send to
  // their tip height
  uint64 count = 2;
}

// Find at which point the chain splits.
message FindChainSplitRequest {
  // A set of block hashes ordered in height descending order from the chain
  // tip.
  repeated bytes block_hashes = 1;
  // The maximum number of headers to return starting at the first header after
  // the matched height
  uint64 header_count = 2;
}

message FindChainSplitResponse {
  // An ordered list of headers starting from next header after the matching
  // hash, up until `FindChainSplitRequest::count`
  repeated tari.core.BlockHeader headers = 1;
  // The index of the hash that matched from
  // `FindChainSplitRequest::block_hashes`. This value could also be used to
  // know how far back a split occurs.
  uint64 fork_hash_index = 2;
}

message SyncKernelsRequest {
  uint64 start = 1;
  bytes end_header_hash = 2;
}

message SyncUtxosRequest {
  // Start header hash to sync UTXOs from
  bytes start_header_hash = 1;
  // End header hash to sync UTXOs to
  bytes end_header_hash = 2;
}

message SyncUtxosResponse {
  oneof txo {
    // The unspent transaction output
    tari.types.TransactionOutput output = 1;
    // If the TXO is spent, the commitment bytes are returned
    bytes commitment = 2;
  }
  bytes mined_header = 3;
}

message SyncUtxosByBlockRequest {
  bytes start_header_hash = 1;
  bytes end_header_hash = 2;
}

message SyncUtxosByBlockResponse {
  repeated tari.types.TransactionOutput outputs = 1;
  uint64 height = 2;
  bytes header_hash = 3;
  uint64 mined_timestamp = 4;
}

message GetMempoolFeePerGramStatsRequest {
  uint64 count = 1;
}

message GetMempoolFeePerGramStatsResponse {
  repeated MempoolFeePerGramStat stats = 1;
}

message MempoolFeePerGramStat {
  uint64 order = 1;
  uint64 max_fee_per_gram = 2;
  uint64 avg_fee_per_gram = 4;
  uint64 min_fee_per_gram = 5;
}

message GetWalletQueryHttpServiceAddressResponse {
  string http_address = 1;
}
