Skip to content
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
17 changes: 14 additions & 3 deletions gen/bitcoin/bitcoind/v1alpha/bitcoin.pb.go

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

2 changes: 2 additions & 0 deletions proto/bitcoin/bitcoind/v1alpha/bitcoin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ message ImportDescriptorsRequest {

uint32 range_start = 3;
uint32 range_end = 4;
// If a ranged descriptor is set to active, this specifies the next index to generate addresses from
uint32 next_index = 8;

// Nil passes 'now' to Bitcoin Core, which bypasses scanning.
google.protobuf.Timestamp timestamp = 5;
Expand Down
16 changes: 16 additions & 0 deletions server/commands/bitcoind.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ type UtxoUpdatePsbt struct {
type JoinPsbts struct {
Psbts []string `json:"psbts"`
}

// ImportDescriptorsRequestItem represents a single descriptor import request
type ImportDescriptorsRequestItem struct {
Descriptor *string `json:"desc,omitempty"`
Active *bool `json:"active,omitempty"`
Range interface{} `json:"range,omitempty"` // Can be int or [int,int]
NextIndex *int `json:"next_index,omitempty"`
Timestamp interface{} `json:"timestamp"` // Can be int64 or "now"
Internal *bool `json:"internal,omitempty"`
Label *string `json:"label,omitempty"`
}

// ImportDescriptorsCmd defines the importdescriptors JSON-RPC command
type ImportDescriptorsCmd struct {
Requests []ImportDescriptorsRequestItem `json:"requests"`
}
40 changes: 22 additions & 18 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

func init() {
btcjson.MustRegisterCmd("importdescriptors", new(btcjson.ImportMultiCmd), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("importdescriptors", new(commands.ImportDescriptorsCmd), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("bumpfee", new(commands.BumpFee), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("analyzepsbt", new(commands.AnalyzePsbt), btcjson.UFWalletOnly)
btcjson.MustRegisterCmd("combinepsbt", new(commands.CombinePsbt), btcjson.UFWalletOnly)
Expand Down Expand Up @@ -1175,28 +1175,27 @@ func (b *Bitcoind) ImportDescriptors(ctx context.Context, c *connect.Request[pb.

return withCancel(
ctx, b.conf, func(ctx context.Context) ([]parsedDescriptorResponse, error) {
cmd := btcjson.ImportMultiCmd{
Requests: lo.Map(c.Msg.Requests, func(req *pb.ImportDescriptorsRequest_Request, idx int) btcjson.ImportMultiRequest {
importReq := btcjson.ImportMultiRequest{
cmd := commands.ImportDescriptorsCmd{
Requests: lo.Map(c.Msg.Requests, func(req *pb.ImportDescriptorsRequest_Request, idx int) commands.ImportDescriptorsRequestItem {
importReq := commands.ImportDescriptorsRequestItem{
Descriptor: &req.Descriptor_,
Timestamp: lo.If(req.Timestamp == nil,
btcjson.TimestampOrNow{
Value: "now",
}).
ElseF(func() btcjson.TimestampOrNow {
return btcjson.TimestampOrNow{
Value: req.Timestamp.AsTime().Unix(),
}
}),
}

// Set timestamp
if req.Timestamp == nil {
importReq.Timestamp = "now"
} else {
importReq.Timestamp = req.Timestamp.AsTime().Unix()
}

// Add range if specified
if req.RangeStart != 0 || req.RangeEnd != 0 {
// Use [start, end] format
rangeVal := &btcjson.DescriptorRange{
Value: []int{int(req.RangeStart), int(req.RangeEnd)},
}
importReq.Range = rangeVal
importReq.Range = []int{int(req.RangeStart), int(req.RangeEnd)}
}

if req.NextIndex != 0 {
nextIndex := int(req.NextIndex)
importReq.NextIndex = &nextIndex
}

// Add internal flag
Expand All @@ -1211,6 +1210,11 @@ func (b *Bitcoind) ImportDescriptors(ctx context.Context, c *connect.Request[pb.
importReq.Label = &label
}

if req.Active {
active := req.Active
importReq.Active = &active
}

return importReq
}),
}
Expand Down
Loading