@@ -8,6 +8,8 @@ import { ProofResult } from "./btcindexer";
88export interface SuiClientConfig {
99 suiNetwork : "testnet" | "mainnet" | "devnet" ;
1010 suiPackageId : string ;
11+ suiModule : string ;
12+ suiFunction : string ;
1113 suiNbtcObjectId : string ;
1214 suiLightClientObjectId : string ;
1315 suiSignerMnemonic : string ;
@@ -17,13 +19,17 @@ export class SuiClient {
1719 private client : Client ;
1820 private signer : Ed25519Keypair ;
1921 private packageId : string ;
22+ private module : string ;
23+ private function : string ;
2024 private nbtcObjectId : string ;
2125 private lightClientObjectId : string ;
2226
2327 constructor ( config : SuiClientConfig ) {
2428 this . client = new Client ( { url : getFullnodeUrl ( config . suiNetwork ) } ) ;
2529 this . signer = Ed25519Keypair . deriveKeypair ( config . suiSignerMnemonic ) ;
2630 this . packageId = config . suiPackageId ;
31+ this . module = config . suiModule ;
32+ this . function = config . suiFunction ;
2733 this . nbtcObjectId = config . suiNbtcObjectId ;
2834 this . lightClientObjectId = config . suiLightClientObjectId ;
2935 }
@@ -35,9 +41,12 @@ export class SuiClient {
3541 proof : ProofResult ,
3642 ) : Promise < void > {
3743 const tx = new SuiTransaction ( ) ;
38- const target = `${ this . packageId } ::nbtc::mint ` as const ;
44+ const target = `${ this . packageId } ::${ this . module } :: ${ this . function } ` as const ;
3945 const serializedTx = serializeBtcTx ( transaction ) ;
4046
47+ // NOTE: the contract is expecting the proofs to be in big-endian format, while the bitcon-js lib operates internally on little-endian.
48+ const proofBigEndian = proof . proofPath . map ( ( p ) => Array . from ( Buffer . from ( p ) . reverse ( ) ) ) ;
49+
4150 tx . moveCall ( {
4251 target : target ,
4352 arguments : [
@@ -49,15 +58,15 @@ export class SuiClient {
4958 tx . pure . u32 ( serializedTx . outputCount ) ,
5059 tx . pure . vector ( "u8" , serializedTx . outputs ) ,
5160 tx . pure . vector ( "u8" , serializedTx . lockTime ) ,
52- tx . pure . vector (
53- "vector<u8>" ,
54- proof . proofPath . map ( ( p ) => Array . from ( p ) ) ,
55- ) ,
61+ tx . pure . vector ( "vector<u8>" , proofBigEndian ) ,
5662 tx . pure . u64 ( blockHeight ) ,
5763 tx . pure . u64 ( txIndex ) ,
5864 ] ,
5965 } ) ;
6066
67+ // TODO: should we move it to config or set it as a constant
68+ tx . setGasBudget ( 1000000000 ) ;
69+
6170 const result = await this . client . signAndExecuteTransaction ( {
6271 signer : this . signer ,
6372 transaction : tx ,
0 commit comments