-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from fghdotio/feat/offline-utxo
feat: implement getRgbppSpvProof for OfflineBtcAssetsDataSource
- Loading branch information
Showing
7 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@rgbpp-sdk/service': minor | ||
--- | ||
|
||
Implement `getRgbppSpvProof` for `OfflineBtcAssetsDataSource`, enabling support for offline unlocking of BTC time lock cells. | ||
|
||
- Add an example demonstrating how to unlock BTC time lock cells offline. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { buildBtcTimeCellsSpentTx, signBtcTimeCellSpentTx } from 'rgbpp'; | ||
import { sendCkbTx, getBtcTimeLockScript, btcTxIdAndAfterFromBtcTimeLockArgs } from 'rgbpp/ckb'; | ||
import { BTC_TESTNET_TYPE, CKB_PRIVATE_KEY, btcService, ckbAddress, collector, isMainnet } from '../../env'; | ||
import { OfflineBtcAssetsDataSource, SpvProofEntry } from 'rgbpp/service'; | ||
|
||
const unlockBtcTimeCell = async ({ btcTimeCellArgs }: { btcTimeCellArgs: string }) => { | ||
const btcTimeCells = await collector.getCells({ | ||
lock: { | ||
...getBtcTimeLockScript(isMainnet, BTC_TESTNET_TYPE), | ||
args: btcTimeCellArgs, | ||
}, | ||
isDataMustBeEmpty: false, | ||
}); | ||
if (!btcTimeCells || btcTimeCells.length === 0) { | ||
throw new Error('No btc time cell found'); | ||
} | ||
|
||
const spvProofs: SpvProofEntry[] = []; | ||
for (const btcTimeCell of btcTimeCells) { | ||
const { btcTxId, after } = btcTxIdAndAfterFromBtcTimeLockArgs(btcTimeCell.output.lock.args); | ||
spvProofs.push({ | ||
txid: btcTxId, | ||
confirmations: after, | ||
proof: await btcService.getRgbppSpvProof(btcTxId, after), | ||
}); | ||
} | ||
|
||
const offlineBtcAssetsDataSource = new OfflineBtcAssetsDataSource({ | ||
txs: [], | ||
utxos: [], | ||
rgbppSpvProofs: spvProofs, | ||
}); | ||
|
||
const ckbRawTx: CKBComponents.RawTransaction = await buildBtcTimeCellsSpentTx({ | ||
btcTimeCells, | ||
btcAssetsApi: offlineBtcAssetsDataSource, | ||
isMainnet, | ||
btcTestnetType: BTC_TESTNET_TYPE, | ||
}); | ||
|
||
const signedTx = await signBtcTimeCellSpentTx({ | ||
secp256k1PrivateKey: CKB_PRIVATE_KEY, | ||
collector, | ||
masterCkbAddress: ckbAddress, | ||
ckbRawTx, | ||
isMainnet, | ||
}); | ||
|
||
const txHash = await sendCkbTx({ collector, signedTx }); | ||
console.info(`BTC time cell has been spent and CKB tx hash is ${txHash}`); | ||
}; | ||
|
||
// The btcTimeCellArgs is from the outputs[0].lock.args(BTC Time lock args) of the 3-btc-leap-ckb.ts CKB transaction | ||
unlockBtcTimeCell({ | ||
btcTimeCellArgs: | ||
'0x7d00000010000000590000005d000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8011400000021e782eeb1c9893b341ed71c2dfe6fa496a6435c0600000045241651e435d786d0ba8a1280d4bb3283eca10db728e2ba0a3978c136f5bb19', | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
777db68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New snapshot version of the rgbpp-sdk packages have been released:
0.0.0-snap-20250124052302
0.0.0-snap-20250124052302
0.0.0-snap-20250124052302
0.0.0-snap-20250124052302