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

Add PSBT field to UnsealedAsset RPC message #1214

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions itest/mint_fund_seal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,17 @@ func unmarshalPendingAssetGroup(t *testing.T,
virtualTx, err := taprpc.UnmarshalGroupVirtualTx(a.GroupVirtualTx)
require.NoError(t, err)

// Ensure that the group virtual tx is the same as the grouped virtual
// PSBT.
groupVmPsbt, err := psbt.NewFromRawBytes(
bytes.NewReader(a.GroupVirtualPsbt), false,
)
require.NoError(t, err)
require.NotNil(t, groupVmPsbt)

require.Equal(t, *groupVmPsbt.UnsignedTx, virtualTx.Tx)

// Unmarshal group key request.
require.NotNil(t, a.GroupKeyRequest)
keyReq, err := taprpc.UnmarshalGroupKeyRequest(a.GroupKeyRequest)
require.NoError(t, err)
Expand Down
33 changes: 27 additions & 6 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4194,9 +4194,10 @@ func marshalUnsealedSeedling(verbose bool,
seedling *tapgarden.UnsealedSeedling) (*mintrpc.UnsealedAsset, error) {

var (
groupVirtualTx *taprpc.GroupVirtualTx
groupReq *taprpc.GroupKeyRequest
err error
groupVirtualTx *taprpc.GroupVirtualTx
groupReq *taprpc.GroupKeyRequest
groupVirtualPsbtBytes []byte
err error
)

rpcSeedling, err := marshalSeedling(seedling.Seedling)
Expand All @@ -4218,12 +4219,32 @@ func marshalUnsealedSeedling(verbose bool,
if err != nil {
return nil, err
}

// Generate PSBT equivalent of the group virtual tx.
groupVirtualPsbt, err := psbt.NewFromUnsignedTx(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really give us anything... This can trivially also be bitcoin-cli converttopsbt <tx>.
If we want to give a signer any chance of being able to sign this, we need to add the minimum amount of metadata we have available:

		groupVirtualPsbt.Inputs[0].WitnessUtxo = &wire.TxOut{
			Value:    0, // Probably needs to be set to the equal amount as the VM TX's output value?
			PkScript: nil, // Needs to be the p2tr script for the script key Taproot key.
		}
		groupVirtualPsbt.Inputs[0].TaprootInternalKey = ? // I think we can set this from the script key's internal key, which I assume we need to know at this point?
		groupVirtualPsbt.Inputs[0].TaprootMerkleRoot = ? // Same as above, should be the tweak of the script key.

		groupVirtualPsbt.Outputs[0].TaprootInternalKey = ? // Same as above.

&seedling.PendingAssetGroup.GroupVirtualTx.Tx,
)
if err != nil {
return nil, fmt.Errorf("error producing group "+
"virtual PSBT from tx: %w", err)
}

// Serialize PSBT to bytes.
var psbtBuf bytes.Buffer
err = groupVirtualPsbt.Serialize(&psbtBuf)
if err != nil {
return nil, fmt.Errorf("error serializing group "+
"virtual PSBT for unsealed seedling: %w", err)
}

groupVirtualPsbtBytes = psbtBuf.Bytes()
}

return &mintrpc.UnsealedAsset{
Asset: rpcSeedling,
GroupVirtualTx: groupVirtualTx,
GroupKeyRequest: groupReq,
Asset: rpcSeedling,
GroupVirtualTx: groupVirtualTx,
GroupVirtualPsbt: groupVirtualPsbtBytes,
GroupKeyRequest: groupReq,
}, nil
}

Expand Down
Loading
Loading