Skip to content

Commit

Permalink
Merge pull request #206 from nautls/arobsn/i205
Browse files Browse the repository at this point in the history
Fixes non-standard token minting register parsing
  • Loading branch information
arobsn authored Sep 24, 2024
2 parents a22e0f1 + 4f7d4f9 commit ad89ce5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 39 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"dependencies": {
"@download/blockies": "^1.0.3",
"@emurgo/cip4-js": "^1.0.7",
"@fleet-sdk/babel-fees-plugin": "^0.1.15",
"@fleet-sdk/blockchain-providers": "^0.6.5",
"@fleet-sdk/babel-fees-plugin": "^0.1.16",
"@fleet-sdk/blockchain-providers": "^0.7.0",
"@fleet-sdk/common": "^0.6.4",
"@fleet-sdk/core": "^0.6.4",
"@fleet-sdk/core": "^0.7.0",
"@fleet-sdk/crypto": "^0.6.4",
"@fleet-sdk/serializer": "^0.6.4",
"@fleet-sdk/wallet": "^0.6.4",
"@fleet-sdk/serializer": "^0.7.0",
"@fleet-sdk/wallet": "^0.7.0",
"@ledgerhq/hw-transport-webusb": "^6.29.2",
"@mdi/js": "^7.4.47",
"@oruga-ui/oruga-next": "0.6.0",
Expand Down
62 changes: 31 additions & 31 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/chains/ergo/services/graphQlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function addressInfoMapper(gqlAddressInfo: Address): AddressInfo {
return mapped;
}

export function parseEIP4Asset(tokenInfo: Token): IAssetInfo {
function parseEIP4Asset(tokenInfo: Token): IAssetInfo {
if (!tokenInfo.box) throw new Error("Asset box info is missing");

const registers = tokenInfo.box.additionalRegisters as Registers;
Expand Down
15 changes: 13 additions & 2 deletions src/chains/ergo/transaction/interpreter/outputInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AddressType, ErgoAddress, Network } from "@fleet-sdk/core";
import { EIP12UnsignedInput, first, isEmpty } from "@fleet-sdk/common";
import { utf8 } from "@fleet-sdk/crypto";
import { isValidBabelContract } from "@fleet-sdk/babel-fees-plugin";
import { decode } from "@fleet-sdk/serializer";
import { ERG_DECIMALS, ERG_TOKEN_ID, MAINNET } from "@/constants/ergo";
import { ErgoBoxCandidate } from "@/types/connector";
import { bn, decimalize } from "@/common/bigNumber";
Expand Down Expand Up @@ -155,8 +156,7 @@ export class OutputInterpreter {
};
}

const decodedDecimals = sigmaDecode(this._box.additionalRegisters["R6"], utf8);
const decimals = decodedDecimals ? parseInt(decodedDecimals) : undefined;
const decimals = decodeDecimals(this._box.additionalRegisters["R6"]);
return {
tokenId: token.tokenId,
name: sigmaDecode(this._box.additionalRegisters["R4"], utf8) ?? "",
Expand All @@ -167,3 +167,14 @@ export class OutputInterpreter {
};
}
}

function decodeDecimals(value: string): number | undefined {
const r6 = decode(value);
if (!r6) return;

if (r6.type.toString() === "SColl[SByte]") {
return Number.parseInt(utf8.encode(r6.data as Uint8Array), 10);
}

return typeof r6.data === "number" ? r6.data : Number(r6.data);
}

0 comments on commit ad89ce5

Please sign in to comment.