Skip to content

Commit

Permalink
drivechain: add list sidechain deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
octobocto committed Sep 25, 2024
1 parent 999a963 commit b312611
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 54 deletions.
362 changes: 308 additions & 54 deletions gen/bitcoin/drivechaind/v1/drivechain.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions proto/bitcoin/drivechaind/v1/drivechain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package bitcoin.drivechaind.v1;
service DrivechainService {
rpc CreateSidechainDeposit(CreateSidechainDepositRequest) returns (CreateSidechainDepositResponse);
rpc ListActiveSidechains(ListActiveSidechainsRequest) returns (ListActiveSidechainsResponse);
rpc ListSidechainDeposits(ListSidechainDepositsRequest) returns (ListSidechainDepositsResponse);
}

message CreateSidechainDepositRequest {
Expand Down Expand Up @@ -36,3 +37,20 @@ message ListActiveSidechainsResponse {

repeated Sidechain sidechains = 1;
}

message ListSidechainDepositsRequest {
int32 slot = 1;
}

message ListSidechainDepositsResponse {
message SidechainDeposit {
int32 nsidechain = 1;
string strdest = 2;
string txhex = 3;
int32 nburnindex = 4;
int32 ntx = 5;
string hashblock = 6;
}

repeated SidechainDeposit deposits = 1;
}
6 changes: 6 additions & 0 deletions server/commands/drivechain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ type ListSidechainCTip struct {
// The sidechain slot
Slot int `json:"slot"`
}

// ListSidechainDeposits retrieves a list of deposits for a specific sidechain
type ListSidechainDeposits struct {
// The sidechain slot
Slot int `json:"slot"`
}
23 changes: 23 additions & 0 deletions server/drivechain_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,26 @@ func chainToSlot(chain string) (int, error) {
return 0, fmt.Errorf("unknown chain: %s", chain)
}
}

// ListSidechainDeposits implements drivechaindv1connect.DrivechainServiceHandler.
func (b *Bitcoind) ListSidechainDeposits(ctx context.Context, c *connect.Request[pb.ListSidechainDepositsRequest]) (*connect.Response[pb.ListSidechainDepositsResponse], error) {
cmd, err := btcjson.NewCmd("listsidechaindeposits", c.Msg.Slot)
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to create listsidechaindeposits command: %w", err))
}

res, err := rpcclient.ReceiveFuture(b.rpc.SendCmd(ctx, cmd))
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to execute listsidechaindeposits command: %w", err))
}

var deposits []*pb.ListSidechainDepositsResponse_SidechainDeposit
err = json.Unmarshal(res, &deposits)
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to unmarshal listsidechaindeposits response: %w", err))
}

return connect.NewResponse(&pb.ListSidechainDepositsResponse{
Deposits: deposits,
}), nil
}
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func init() {
btcjson.MustRegisterCmd("createsidechaindeposit", new(commands.CreateSidechainDeposit), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("listactivesidechains", new(commands.ListActiveSidechains), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("listsidechainctip", new(commands.ListSidechainCTip), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("listsidechaindeposits", new(commands.ListSidechainDeposits), btcjson.UFWalletOnly)
}

type Bitcoind struct {
Expand Down

0 comments on commit b312611

Please sign in to comment.