Skip to content

Commit

Permalink
Merge branch '60-improve-ergochain-extractsignedtransactionorder' int…
Browse files Browse the repository at this point in the history
…o 'dev'

update ErgoChain

Closes #60

See merge request ergo/rosen-bridge/rosen-chains!67
  • Loading branch information
zargarzadehm committed Oct 3, 2023
2 parents 6abffae + 204e60a commit 77363ab
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions packages/chains/ergo/lib/ErgoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -977,13 +977,15 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {

/**
* 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++) {
Expand Down Expand Up @@ -1023,6 +1025,20 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
*/
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<string> =>
Buffer.from(
Serializer.signedSerialize(
await this.network.getTransaction(txId, blockId)
)
).toString('hex');
}

export default ErgoChain;
2 changes: 1 addition & 1 deletion packages/chains/ergo/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 7 additions & 11 deletions packages/chains/ergo/tests/ErgoChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/networks/ergo-explorer/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/networks/ergo-node/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit 77363ab

Please sign in to comment.