From 204e60a12de3dd96d62370c144c3552267e1303e Mon Sep 17 00:00:00 2001 From: HFazelinia Date: Tue, 3 Oct 2023 16:05:54 +0100 Subject: [PATCH] update ErgoChain - update `extractSignedTransactionOrder` to get serializedTx as input arg - add `getTransaction` function to get serialiezdTx from blockchain --- package-lock.json | 10 ++++----- packages/chains/ergo/lib/ErgoChain.ts | 22 +++++++++++++++++--- packages/chains/ergo/package.json | 2 +- packages/chains/ergo/tests/ErgoChain.spec.ts | 18 +++++++--------- packages/networks/ergo-explorer/package.json | 4 ++-- packages/networks/ergo-node/package.json | 4 ++-- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 64bd091..af42521 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8456,7 +8456,7 @@ }, "packages/chains/ergo": { "name": "@rosen-chains/ergo", - "version": "2.1.0", + "version": "2.2.0", "license": "GPL-3.0", "dependencies": { "@rosen-bridge/json-bigint": "^0.1.0", @@ -8531,7 +8531,7 @@ }, "packages/networks/ergo-explorer": { "name": "@rosen-chains/ergo-explorer-network", - "version": "2.1.0", + "version": "2.2.0", "license": "GPL-3.0", "dependencies": { "@rosen-bridge/json-bigint": "^0.1.0", @@ -8539,7 +8539,7 @@ "@rosen-bridge/rosen-extractor": "^1.0.0", "@rosen-bridge/tokens": "^1.0.0", "@rosen-chains/abstract-chain": "^2.1.0", - "@rosen-chains/ergo": "^2.1.0", + "@rosen-chains/ergo": "^2.2.0", "@rosen-clients/ergo-explorer": "^1.0.2", "ergo-lib-wasm-nodejs": "^0.24.1", "it-all": "^3.0.1" @@ -8573,7 +8573,7 @@ }, "packages/networks/ergo-node": { "name": "@rosen-chains/ergo-node-network", - "version": "2.1.1", + "version": "2.2.0", "license": "GPL-3.0", "dependencies": { "@rosen-bridge/json-bigint": "^0.1.0", @@ -8581,7 +8581,7 @@ "@rosen-bridge/rosen-extractor": "^1.0.0", "@rosen-bridge/tokens": "^1.0.0", "@rosen-chains/abstract-chain": "^2.1.0", - "@rosen-chains/ergo": "^2.1.0", + "@rosen-chains/ergo": "^2.2.0", "@rosen-clients/ergo-node": "^1.0.3", "ergo-lib-wasm-nodejs": "^0.24.1", "it-all": "^3.0.1" diff --git a/packages/chains/ergo/lib/ErgoChain.ts b/packages/chains/ergo/lib/ErgoChain.ts index 7a0bbb8..a5700cd 100644 --- a/packages/chains/ergo/lib/ErgoChain.ts +++ b/packages/chains/ergo/lib/ErgoChain.ts @@ -977,13 +977,15 @@ class ErgoChain extends AbstractUtxoChain { /** * extracts payment order of a signed transaction - * @param signedTransaction The PaymentTransaction + * @param serializedTransaction hex representation of sigma-serialized-bytes of the transaction * @returns the transaction payment order (list of single payments) */ extractSignedTransactionOrder = ( - signedTransaction: PaymentTransaction + serializedTransaction: string ): PaymentOrder => { - const tx = Serializer.signedDeserialize(signedTransaction.txBytes); + const tx = Serializer.signedDeserialize( + Buffer.from(serializedTransaction, 'hex') + ); const order: PaymentOrder = []; for (let i = 0; i < tx.outputs().len(); i++) { @@ -1023,6 +1025,20 @@ class ErgoChain extends AbstractUtxoChain { */ PaymentTransactionFromJson = (jsonString: string): ErgoTransaction => ErgoTransaction.fromJson(jsonString); + + /** + * get a transaction by its id + * returning serialized tx or throw an error + * if the tx doesn't belong to the block + * @param txId + * @param blockId + */ + getTransaction = async (txId: string, blockId: string): Promise => + Buffer.from( + Serializer.signedSerialize( + await this.network.getTransaction(txId, blockId) + ) + ).toString('hex'); } export default ErgoChain; diff --git a/packages/chains/ergo/package.json b/packages/chains/ergo/package.json index f7099d4..f9ef200 100644 --- a/packages/chains/ergo/package.json +++ b/packages/chains/ergo/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/ergo", - "version": "2.1.0", + "version": "2.2.0", "description": "this project contains ergo chain for Rosen-bridge", "main": "dist/lib/index.js", "types": "dist/lib/index.d.ts", diff --git a/packages/chains/ergo/tests/ErgoChain.spec.ts b/packages/chains/ergo/tests/ErgoChain.spec.ts index a8f8cf1..896f43e 100644 --- a/packages/chains/ergo/tests/ErgoChain.spec.ts +++ b/packages/chains/ergo/tests/ErgoChain.spec.ts @@ -2432,24 +2432,20 @@ describe('ErgoChain', () => { * order successfully * @dependencies * @scenario - * - mock PaymentTransaction + * - mock serialized transaction * - run test * - check returned value * @expected * - it should return mocked transaction order */ it('should extract transaction order successfully', () => { - // mock PaymentTransaction - const paymentTx = new ErgoTransaction( - 'txId', - 'eventId', + // mock serialized transaction + const serializedTx = Buffer.from( ergoTestUtils .toTransaction(transactionTestData.transaction0) - .sigma_serialize_bytes(), - TransactionType.payment, - [], - [] - ); + .sigma_serialize_bytes() + ).toString('hex'); + const expectedOrder = transactionTestData.transaction0Order; const config: ErgoConfigs = { fee: 1100000n, @@ -2476,7 +2472,7 @@ describe('ErgoChain', () => { feeRatioDivisor, signFunction ); - const result = ergoChain.extractSignedTransactionOrder(paymentTx); + const result = ergoChain.extractSignedTransactionOrder(serializedTx); // check returned value expect(result).toEqual(expectedOrder); diff --git a/packages/networks/ergo-explorer/package.json b/packages/networks/ergo-explorer/package.json index 11c3c4c..0c03cf8 100644 --- a/packages/networks/ergo-explorer/package.json +++ b/packages/networks/ergo-explorer/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/ergo-explorer-network", - "version": "2.1.0", + "version": "2.2.0", "description": "ergo explorer network package for rosen ergo chain", "main": "dist/lib/index.js", "types": "dist/lib/index.d.ts", @@ -25,7 +25,7 @@ "@rosen-bridge/rosen-extractor": "^1.0.0", "@rosen-bridge/tokens": "^1.0.0", "@rosen-chains/abstract-chain": "^2.1.0", - "@rosen-chains/ergo": "^2.1.0", + "@rosen-chains/ergo": "^2.2.0", "@rosen-clients/ergo-explorer": "^1.0.2", "ergo-lib-wasm-nodejs": "^0.24.1", "it-all": "^3.0.1" diff --git a/packages/networks/ergo-node/package.json b/packages/networks/ergo-node/package.json index f574645..fd7829c 100644 --- a/packages/networks/ergo-node/package.json +++ b/packages/networks/ergo-node/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/ergo-node-network", - "version": "2.1.1", + "version": "2.2.0", "description": "ergo node network package for rosen ergo chain", "main": "dist/lib/index.js", "types": "dist/lib/index.d.ts", @@ -25,7 +25,7 @@ "@rosen-bridge/rosen-extractor": "^1.0.0", "@rosen-bridge/tokens": "^1.0.0", "@rosen-chains/abstract-chain": "^2.1.0", - "@rosen-chains/ergo": "^2.1.0", + "@rosen-chains/ergo": "^2.2.0", "@rosen-clients/ergo-node": "^1.0.3", "ergo-lib-wasm-nodejs": "^0.24.1", "it-all": "^3.0.1"