Skip to content

Commit

Permalink
Merge pull request #49 from ckb-cell/fix/paymaster
Browse files Browse the repository at this point in the history
fix(rgbpp-sdk/ckb): Update paymaster tx WitnessArgs
  • Loading branch information
duanyytop authored Mar 25, 2024
2 parents 7c9a358 + 7794d9a commit c1e5d6c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/ckb/src/rgbpp/ckb-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ export const appendCkbTxWitnesses = async ({
return rawTx;
};

const parseWitness = (witness: StructuredWitness) =>
typeof witness === 'string' ? witness : serializeWitnessArgs(witness);

/**
* Append paymaster cell to the ckb transaction inputs and sign the transaction with paymaster cell's secp256k1 private key
* @param secp256k1PrivateKey The Secp256k1 private key of the paymaster cells maintainer
Expand All @@ -96,7 +93,7 @@ export const appendPaymasterCellAndSignCkbTx = async ({
paymasterCell,
isMainnet,
}: AppendPaymasterCellAndSignTxParams): Promise<CKBComponents.RawTransaction> => {
let rawTx = ckbRawTx;
let rawTx = ckbRawTx as CKBComponents.RawTransactionToSign;
const paymasterInput = { previousOutput: paymasterCell.outPoint, since: '0x0' };
rawTx.inputs = [paymasterInput, ...rawTx.inputs];
const inputsCapacity = BigInt(sumInputsCapacity) + BigInt(paymasterCell.output.capacity);
Expand All @@ -118,23 +115,26 @@ export const appendPaymasterCellAndSignCkbTx = async ({
keyMap.set(scriptToHash(paymasterCell.output.lock), secp256k1PrivateKey);
keyMap.set(scriptToHash(getRgbppLockScript(isMainnet)), '');

const cells = ckbRawTx.inputs.map((input, index) => ({
const cells = rawTx.inputs.map((input, index) => ({
outPoint: input.previousOutput,
lock: index === 0 ? paymasterCell.output.lock : getRgbppLockScript(isMainnet),
}));

const emptyWitness = { lock: '', inputType: '', outputType: '' };
rawTx.witnesses = [emptyWitness, ...rawTx.witnesses];

const transactionHash = rawTransactionToHash(rawTx);
const signedWitnesses = signWitnesses(keyMap)({
transactionHash,
witnesses: rawTx.witnesses,
inputCells: cells,
skipMissingKeys: true,
});
const emptyWitness = { lock: '', inputType: '', outputType: '' };

const signedTx = {
...rawTx,
witnesses: signedWitnesses.map((witness, index) =>
index === 0 ? serializeWitnessArgs(emptyWitness) : parseWitness(witness),
witnesses: signedWitnesses.map((witness) =>
typeof witness !== 'string' ? serializeWitnessArgs(witness) : witness,
),
};
return signedTx;
Expand Down

1 comment on commit c1e5d6c

@github-actions
Copy link

Choose a reason for hiding this comment

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

[{"name":"@rgbpp-sdk/btc","version":"0.0.0-snap-20240325110744"},{"name":"@rgbpp-sdk/ckb","version":"0.0.0-snap-20240325110744"}]

Please sign in to comment.