syntax = "proto3";

package publicrpc.v1;

option go_package = "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1;publicrpcv1";

import "gossip/v1/gossip.proto";
import "google/api/annotations.proto";

enum ChainID {
  CHAIN_ID_UNSPECIFIED = 0;
  CHAIN_ID_SOLANA = 1;
  CHAIN_ID_ETHEREUM = 2;
  CHAIN_ID_TERRA = 3;
  CHAIN_ID_BSC = 4;
}

// MessageID is a VAA's globally unique identifier (see data availability design document).
message MessageID {
  // Emitter chain ID.
  ChainID emitter_chain = 1;
  // Hex-encoded (without leading 0x) emitter address.
  string emitter_address = 2;
  // Sequence number for (emitter_chain, emitter_address).
  int64 sequence = 3;
}

// PublicRPCService service exposes endpoints to be consumed externally; GUIs, historical record keeping, etc.
service PublicRPCService {
  // GetLastHeartbeats returns the last heartbeat received for each guardian node in the
  // node's active guardian set. Heartbeats received by nodes not in the guardian set are ignored.
  // The heartbeat value is null if no heartbeat has yet been received.
  rpc GetLastHeartbeats (GetLastHeartbeatsRequest) returns (GetLastHeartbeatsResponse) {
    option (google.api.http) = {
      get: "/v1/heartbeats"
    };
  }

  rpc GetSignedVAA (GetSignedVAARequest) returns (GetSignedVAAResponse) {
    option (google.api.http) = {
      get: "/v1/signed_vaa/{message_id.emitter_chain}/{message_id.emitter_address}/{message_id.sequence}"
    };
  }

  rpc GetCurrentGuardianSet (GetCurrentGuardianSetRequest) returns (GetCurrentGuardianSetResponse) {
    option (google.api.http) = {
      get: "/v1/guardianset/current"
    };
  }

}

message GetSignedVAARequest {
  MessageID message_id = 1;
}

message GetSignedVAAResponse {
  bytes vaa_bytes = 1;
}

message GetLastHeartbeatsRequest {
}

message GetLastHeartbeatsResponse {
  message Entry {
    // Verified, hex-encoded (with leading 0x) guardian address. This is the guardian address
    // which signed this heartbeat. The GuardianAddr field inside the heartbeat
    // is NOT verified - remote nodes can put arbitrary data in it.
    string verified_guardian_addr = 1;

    // Base58-encoded libp2p node address that sent this heartbeat, used to
    // distinguish between multiple nodes running for the same guardian.
    string p2p_node_addr = 2;

    // Raw heartbeat received from the network. Data is only as trusted
    // as the guardian node that sent it - none of the fields are verified.
    gossip.v1.Heartbeat raw_heartbeat = 3;
  }

  repeated Entry entries = 1;
}

message GetCurrentGuardianSetRequest {
}

message GetCurrentGuardianSetResponse {
  GuardianSet guardian_set = 1;
}

message GuardianSet {
  // Guardian set index
  uint32 index = 1;
  // List of guardian addresses as human-readable hex-encoded (leading 0x) addresses.
  repeated string addresses = 2;
}
