Skip to content

Commit

Permalink
taprpc+tapfreighter: update FundAddressSend to accept prevIds
Browse files Browse the repository at this point in the history
  • Loading branch information
habibitcoin committed Nov 8, 2024
1 parent e6b78bd commit baed202
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
28 changes: 25 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2049,9 +2049,31 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,

case req.GetRaw() != nil:
raw := req.GetRaw()
prevIDs := []asset.PrevID{}
if len(raw.Inputs) > 0 {
return nil, fmt.Errorf("template inputs not yet " +
"supported")
for _, input := range raw.Inputs {
// Create a new chainhash.Hash and set its bytes
var hash chainhash.Hash
err := hash.SetBytes(input.Outpoint.Txid)
if err != nil {
return nil, fmt.Errorf(
"invalid Txid length: %w", err,
)
}
// Decode the input into an asset.PrevID
outpoint := wire.OutPoint{
Hash: hash,
Index: input.Outpoint.OutputIndex,
}
prevID := asset.PrevID{
OutPoint: outpoint,
ID: asset.ID(input.Id),
ScriptKey: asset.SerializedKey(
input.ScriptKey,
),
}
prevIDs = append(prevIDs, prevID)
}
}
if len(raw.Recipients) > 1 {
return nil, fmt.Errorf("only one recipient supported")
Expand All @@ -2074,7 +2096,7 @@ func (r *rpcServer) FundVirtualPsbt(ctx context.Context,
}

fundedVPkt, err = r.cfg.AssetWallet.FundAddressSend(
ctx, coinSelectType, addr,
ctx, coinSelectType, prevIDs, addr,
)
if err != nil {
return nil, fmt.Errorf("error funding address send: "+
Expand Down
2 changes: 1 addition & 1 deletion tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
"address parcel")
}
fundSendRes, err := p.cfg.AssetWallet.FundAddressSend(
ctx, tapsend.Bip86Only, addrParcel.destAddrs...,
ctx, tapsend.Bip86Only, nil, addrParcel.destAddrs...,
)
if err != nil {
return nil, fmt.Errorf("unable to fund address send: "+
Expand Down
2 changes: 2 additions & 0 deletions tapfreighter/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Wallet interface {
// selected assets.
FundAddressSend(ctx context.Context,
coinSelectType tapsend.CoinSelectType,
prevIDs []asset.PrevID,
receiverAddrs ...*address.Tap) (*FundedVPacket, error)

// FundPacket funds a virtual transaction, selecting assets to spend
Expand Down Expand Up @@ -236,6 +237,7 @@ type FundedVPacket struct {
// NOTE: This is part of the Wallet interface.
func (f *AssetWallet) FundAddressSend(ctx context.Context,
coinSelectType tapsend.CoinSelectType,
prevIDs []asset.PrevID,
receiverAddrs ...*address.Tap) (*FundedVPacket, error) {

// We start by creating a new virtual transaction that will be used to
Expand Down

0 comments on commit baed202

Please sign in to comment.