Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivechain: add list sidechain deposits #26

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading