Skip to content

Commit

Permalink
Merge branch '39-ergo-box-info' into 'dev'
Browse files Browse the repository at this point in the history
Add ergo chain getSerializedBoxInfo

Closes #39

See merge request ergo/rosen-bridge/rosen-chains!37
  • Loading branch information
vorujack committed Jul 26, 2023
2 parents a63d0de + 69d097c commit b73cc75
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 29 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/abstract-chain/lib/AbstractUtxoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class AbstractUtxoChain<BoxType> extends AbstractChain {
* @param box the box
* @returns an object containing the box id and assets
*/
abstract getBoxInfo: (box: BoxType) => BoxInfo;
protected abstract getBoxInfo: (box: BoxType) => BoxInfo;

/**
* gets useful, allowable and last boxes for an address until required assets are satisfied
Expand Down
2 changes: 1 addition & 1 deletion packages/abstract-chain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rosen-chains/abstract-chain",
"version": "0.1.10",
"version": "0.1.11",
"description": "this project contains abstract classes to implement any chain for Rosen-bridge",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/chains/cardano/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rosen-chains/cardano",
"version": "0.1.10",
"version": "0.1.11",
"description": "this project contains cardano chain for Rosen-bridge",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand All @@ -23,7 +23,7 @@
"@emurgo/cardano-serialization-lib-nodejs": "^11.3.1",
"@rosen-bridge/logger-interface": "^0.1.0",
"@rosen-bridge/rosen-extractor": "^0.1.8",
"@rosen-chains/abstract-chain": "^0.1.10",
"@rosen-chains/abstract-chain": "^0.1.11",
"bech32": "^2.0.0",
"blake2b": "^2.1.3",
"json-bigint": "^1.0.0"
Expand Down
15 changes: 15 additions & 0 deletions packages/chains/ergo/lib/ErgoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,21 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
return BigInt(box.tokens().get(0).amount().as_i64().to_str());
};

/**
* gets box info from a serialized box
* @param serializedBox the serialized string of the box
* @returns box id and assets
*/
getSerializedBoxInfo = (serializedBox: string): BoxInfo => {
// deserialize box
const box = wasm.ErgoBox.sigma_parse_bytes(
Buffer.from(serializedBox, 'hex')
);

// get box info
return this.getBoxInfo(box);
};

/**
* generates mapping from input box id to serialized string of output box (filtered by address, containing the token)
* @param transactions list of transactions
Expand Down
4 changes: 2 additions & 2 deletions packages/chains/ergo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rosen-chains/ergo",
"version": "0.1.15",
"version": "0.1.16",
"description": "this project contains ergo chain for Rosen-bridge",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand All @@ -22,7 +22,7 @@
"dependencies": {
"@rosen-bridge/minimum-fee": "^0.1.10",
"@rosen-bridge/rosen-extractor": "^0.1.8",
"@rosen-chains/abstract-chain": "^0.1.10",
"@rosen-chains/abstract-chain": "^0.1.11",
"blakejs": "^1.2.1",
"ergo-lib-wasm-nodejs": "^0.24.0",
"json-bigint": "^1.0.0"
Expand Down
34 changes: 34 additions & 0 deletions packages/chains/ergo/tests/ErgoChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,40 @@ describe('ErgoChain', () => {
});
});

describe('getSerializedBoxInfo', () => {
const network = new TestErgoNetwork();

/**
* @target ErgoChain.getSerializedBoxInfo should get box id and assets successfully
* @dependencies
* @scenario
* - mock an ErgoBox with assets
* - construct serialized box and BoxInfo
* - run test
* - check returned value
* @expected
* - it should return constructed BoxInfo
*/
it('should get box id and assets successfully', () => {
// mock an ErgoBox with assets
const box = ergoTestUtils.toErgoBox(boxTestData.ergoBox1);
const serializedBox = Buffer.from(box.sigma_serialize_bytes()).toString(
'hex'
);
const boxInfo: BoxInfo = {
id: box.box_id().to_str(),
assets: boxTestData.box1Assets,
};

// run test
const ergoChain = generateChainObject(network);
const result = ergoChain.getSerializedBoxInfo(serializedBox);

// check returned value
expect(result).toEqual(boxInfo);
});
});

describe('getGuardsConfigBox', () => {
/**
* @target ErgoChain.getGuardsConfigBox should get guard box successfully
Expand Down
6 changes: 3 additions & 3 deletions packages/networks/cardano-koios/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rosen-chains/cardano-koios-network",
"version": "0.1.7",
"version": "0.1.8",
"description": "cardano koios network package for rosen cardano chain",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand All @@ -24,8 +24,8 @@
"@rosen-bridge/logger-interface": "^0.1.0",
"@rosen-bridge/rosen-extractor": "^0.1.8",
"@rosen-bridge/tokens": "^0.1.12",
"@rosen-chains/abstract-chain": "^0.1.10",
"@rosen-chains/cardano": "^0.1.10",
"@rosen-chains/abstract-chain": "^0.1.11",
"@rosen-chains/cardano": "^0.1.11",
"@rosen-clients/cardano-koios": "^0.2.2",
"json-bigint": "^1.0.0"
},
Expand Down
6 changes: 3 additions & 3 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": "0.1.10",
"version": "0.1.11",
"description": "ergo explorer network package for rosen ergo chain",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand All @@ -23,8 +23,8 @@
"@rosen-bridge/logger-interface": "^0.1.0",
"@rosen-bridge/rosen-extractor": "^0.1.8",
"@rosen-bridge/tokens": "^0.1.12",
"@rosen-chains/abstract-chain": "^0.1.10",
"@rosen-chains/ergo": "^0.1.15",
"@rosen-chains/abstract-chain": "^0.1.11",
"@rosen-chains/ergo": "^0.1.16",
"@rosen-clients/ergo-explorer": "^0.3.0",
"ergo-lib-wasm-nodejs": "^0.24.0",
"it-all": "^3.0.1",
Expand Down
6 changes: 3 additions & 3 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": "0.1.12",
"version": "0.1.13",
"description": "ergo node network package for rosen ergo chain",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand All @@ -23,8 +23,8 @@
"@rosen-bridge/logger-interface": "^0.1.0",
"@rosen-bridge/rosen-extractor": "^0.1.8",
"@rosen-bridge/tokens": "^0.1.12",
"@rosen-chains/abstract-chain": "^0.1.10",
"@rosen-chains/ergo": "^0.1.15",
"@rosen-chains/abstract-chain": "^0.1.11",
"@rosen-chains/ergo": "^0.1.16",
"@rosen-clients/ergo-node": "^0.3.2",
"ergo-lib-wasm-nodejs": "^0.24.0",
"it-all": "^3.0.1",
Expand Down

0 comments on commit b73cc75

Please sign in to comment.