diff --git a/modules/sdk-coin-ton/src/lib/transaction.ts b/modules/sdk-coin-ton/src/lib/transaction.ts index 681788cf8c..31cbf5c44f 100644 --- a/modules/sdk-coin-ton/src/lib/transaction.ts +++ b/modules/sdk-coin-ton/src/lib/transaction.ts @@ -59,12 +59,14 @@ export class Transaction extends BaseTransaction { const signingMessage = this.createSigningMessage(WALLET_ID, this.seqno, this.expireTime); const sendMode = 3; signingMessage.bits.writeUint8(sendMode); - signingMessage.refs.push(this.createOutMsg(this.recipient.address, this.recipient.amount, this.message)); + const outMsg = this.createOutMsg(this.recipient.address, this.recipient.amount, this.message); + signingMessage.refs.push(outMsg); this.unsignedMessage = Buffer.from(await signingMessage.hash()).toString('hex'); const signature = this._signatures.length > 0 ? this._signatures[0] : Buffer.from(new Uint8Array(64)).toString('hex'); const finalMessage = await this.createExternalMessage(signingMessage, this.seqno, signature); + this.finalMessage = TonWeb.utils.bytesToBase64(await finalMessage.toBoc(false)); this._id = TonWeb.utils.bytesToBase64(await finalMessage.hash()); diff --git a/modules/sdk-coin-ton/src/lib/transactionBuilder.ts b/modules/sdk-coin-ton/src/lib/transactionBuilder.ts index 2328e65e79..505edb5a81 100644 --- a/modules/sdk-coin-ton/src/lib/transactionBuilder.ts +++ b/modules/sdk-coin-ton/src/lib/transactionBuilder.ts @@ -45,7 +45,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder { /** @inheritDoc */ addSignature(publicKey: BasePublicKey, signature: Buffer): void { - this.transaction.signature.push(signature.toString('hex')); + this.transaction.signature[0] = signature.toString('hex'); } /** @@ -73,12 +73,6 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder { /** @inheritdoc */ protected async buildImplementation(): Promise { await this.transaction.build(); - // if (this.si) { - // this.transaction.sign(this._signer); - // } - // if (this._signatures?.length > 0) { - // this.transaction.constructSignedPayload(this._signatures[0].signature); - // } this.transaction.loadInputsAndOutputs(); return this.transaction; } diff --git a/modules/sdk-coin-ton/test/unit/transferBuilder.ts b/modules/sdk-coin-ton/test/unit/transferBuilder.ts index f14b354190..aa0f5135b5 100644 --- a/modules/sdk-coin-ton/test/unit/transferBuilder.ts +++ b/modules/sdk-coin-ton/test/unit/transferBuilder.ts @@ -41,6 +41,7 @@ describe('Ton Transfer Builder', () => { it('should build a send from rawTx', async function () { const txBuilder = factory.from(testData.signedTransaction.tx); const builtTx = await txBuilder.build(); + const jsonTx = builtTx.toJson(); should.equal(builtTx.type, TransactionType.Send); should.equal(builtTx.signablePayload.toString('base64'), testData.signedTransaction.signable); // should.equal(builtTx.id, testData.signedTransaction.txId); @@ -50,7 +51,6 @@ describe('Ton Transfer Builder', () => { should.equal(builtTx.toBroadcastFormat(), testData.signedTransaction.tx); builtTx.inputs.length.should.equal(1); builtTx.outputs.length.should.equal(1); - const jsonTx = builtTx.toJson(); jsonTx.sender.should.equal('EQCSBjR3fUOL98WTw2F_IT4BrcqjZJWVLWUSz5WQDpaL9Jpl'); jsonTx.destination.should.equal('EQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBXwtG'); jsonTx.amount.should.equal('10000000'); @@ -82,16 +82,14 @@ describe('Ton Transfer Builder', () => { should.equal(tx.type, TransactionType.Send); const signable = tx.signablePayload; const signature = keyPair.signMessageinUint8Array(signable); - txBuilder.addSignature(keyPair.getKeys(), Buffer.from(signature)); const signedTx = await txBuilder.build(); const builder2 = factory.from(signedTx.toBroadcastFormat()); + builder2.addSignature(keyPair.getKeys(), Buffer.from(signature)); const tx2 = await builder2.build(); const signature2 = keyPair.signMessageinUint8Array(tx2.signablePayload); should.equal(Buffer.from(signature).toString('hex'), Buffer.from(signature2).toString('hex')); - should.equal(tx.toBroadcastFormat(), tx2.toBroadcastFormat()); - await new Promise((resolve) => setTimeout(resolve, 2000)); - const result = await tonweb.provider.sendBoc(signedTx.toBroadcastFormat()); + const result = await tonweb.provider.sendBoc(tx2.toBroadcastFormat()); console.log(JSON.stringify(result)); });