Skip to content

Commit

Permalink
Merge branch '35-fix-generatetransaction-tx-is-burning-token-in-some-…
Browse files Browse the repository at this point in the history
…cases' into 'dev'

fix token burning cases in Cardano

Closes #35

See merge request ergo/rosen-bridge/rosen-chains!35
  • Loading branch information
vorujack committed Jul 4, 2023
2 parents a46e8e3 + b48a56e commit e60467a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions packages/chains/cardano/lib/CardanoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ class CardanoChain extends AbstractUtxoChain<CardanoUtxo> {
const inputBoxesAssets = CardanoUtils.calculateInputBoxesAssets(bankBoxes);
const changeBoxMultiAsset = CardanoWasm.MultiAsset.new();
inputBoxesAssets.assets.forEach((value, key) => {
const assetInfo = key.split(',');
const assetName = CardanoWasm.AssetName.new(
Buffer.from(key.assetName, 'hex')
Buffer.from(assetInfo[1], 'hex')
);
const policyId = CardanoWasm.ScriptHash.from_hex(key.policyId);
const policyId = CardanoWasm.ScriptHash.from_hex(assetInfo[0]);
const fingerprint = CardanoUtils.createFingerprint(policyId, assetName);
const spentValue = CardanoUtils.bigIntToBigNum(
orderAssets.get(fingerprint) || 0n
Expand Down Expand Up @@ -364,7 +365,7 @@ class CardanoChain extends AbstractUtxoChain<CardanoUtxo> {
}

let outputAssets: AssetBalance = {
nativeToken: 0n,
nativeToken: BigInt(tx.body().fee().to_str()),
tokens: [],
};
for (let i = 0; i < txBody.outputs().len(); i++) {
Expand Down
7 changes: 2 additions & 5 deletions packages/chains/cardano/lib/CardanoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ class CardanoUtils {
static calculateInputBoxesAssets = (
boxes: CardanoUtxo[]
): UtxoBoxesAssets => {
const assets: Map<CardanoAssetInfo, BigNum> = new Map();
const assets: Map<string, BigNum> = new Map();
let changeBoxLovelace: CardanoWasm.BigNum = CardanoWasm.BigNum.zero();
boxes.forEach((box) => {
changeBoxLovelace = changeBoxLovelace.checked_add(
this.bigIntToBigNum(box.value)
);

box.assets.forEach((boxAsset) => {
const assetsInfo: CardanoAssetInfo = {
policyId: boxAsset.policy_id,
assetName: boxAsset.asset_name,
};
const assetsInfo = `${boxAsset.policy_id},${boxAsset.asset_name}`;
const currentValue =
assets.get(assetsInfo) || CardanoWasm.BigNum.zero();

Expand Down
4 changes: 2 additions & 2 deletions packages/chains/cardano/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChainConfigs } from '@rosen-chains/abstract-chain';
import { BigNum, MultiAsset } from '@emurgo/cardano-serialization-lib-nodejs';
import { BigNum } from '@emurgo/cardano-serialization-lib-nodejs';

interface CardanoConfigs extends ChainConfigs {
minBoxValue: bigint;
Expand Down Expand Up @@ -43,7 +43,7 @@ interface CardanoTx {

interface UtxoBoxesAssets {
lovelace: BigNum;
assets: Map<CardanoAssetInfo, BigNum>;
assets: Map<string, BigNum>;
}

export {
Expand Down
2 changes: 1 addition & 1 deletion 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.9",
"version": "0.1.10",
"description": "this project contains cardano chain for Rosen-bridge",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/chains/cardano/tests/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const transaction1Id =
'0066ad9bffa8579a6a7b6f5b6d8fdab20107eca2a2f8435235271173532acab1';

export const transaction1Assets: AssetBalance = {
nativeToken: 139010000n,
nativeToken: 140010000n,
tokens: [
{
id: 'asset1jy5q5a0vpstutq5q6d8cgdmrd4qu5yefcdnjgz',
Expand Down
4 changes: 2 additions & 2 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.6",
"version": "0.1.7",
"description": "cardano koios network package for rosen cardano chain",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand All @@ -25,7 +25,7 @@
"@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.9",
"@rosen-chains/cardano": "^0.1.10",
"@rosen-clients/cardano-koios": "^0.2.2",
"json-bigint": "^1.0.0"
},
Expand Down

0 comments on commit e60467a

Please sign in to comment.