Skip to content
This repository was archived by the owner on Oct 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 2.1


executors:
base:
docker:
- image: circleci/node:12.13.0
- image: hiddentao/erdnet:latest
command: /home/erd/elrondsdk/erdpy testnet start

commands:
install_node_modules:
parameters:
executor:
type: string
steps:
- restore_cache:
name: Restore npm cache
key: << parameters.executor >>-npm-cache-{{ checksum "package-json.lock" }}
- run:
name: Install dependencies
command: npm install
- save_cache:
name: Save npm cache
key: << parameters.executor >>-npm-cache-{{ checksum "package-json.lock" }}
paths:
- ~/.npm

jobs:
build_and_test:
executor: base
working_directory: ~/repo
steps:
- checkout:
path: ~/repo
- install_node_modules:
executor: package
- run:
name: Build outputs
command: yarn build
- run:
name: Testing
command: yarn test
- persist_to_workspace:
root: ~/repo
paths: .

workflows:
version: 2
ci:
jobs:
- build_and_test
4 changes: 4 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ export interface TransactionOnChain extends Transaction {
* Smart contract error messages.
*/
smartContractErrors: string[],
/**
* Smart contract results.
*/
smartContractResults: any[],
/**
* Transaction result status.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export const stringToHex = (arg: string): string => {
}


/**
* Convert Hex string to its ASCII representation.
* @param arg hex string.
*/
export const hexToString = (arg: string): string => {
return Buffer.from(arg, 'hex').toString('utf8')
}



/**
* Convert number to its HEX representation.
*
Expand Down Expand Up @@ -125,3 +135,4 @@ export const queryResultValueToHex = (val: string) => Buffer.from(val, 'base64')
* @internal
*/
export const queryResultValueToString = (val: string) => Buffer.from(val, 'base64').toString('utf8')

3 changes: 2 additions & 1 deletion src/provider/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export const parseRawTransaction = (tx: any): TransactionOnChain => {

return {
raw: tx,
...tx,
...tx,
smartContractResults,
smartContractErrors,
status,
}
Expand Down
33 changes: 23 additions & 10 deletions src/token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
} from '../common'


import { stringToHex, numberToHex, addressToHexString, ARGS_DELIMITER, joinDataArguments, TransactionOptionsBase, TransactionBuilder, convertMapToDataArguments, hexStringToAddress, queryResultValueToHex } from '../lib'
import { stringToHex, numberToHex, addressToHexString, ARGS_DELIMITER, joinDataArguments, TransactionOptionsBase, TransactionBuilder, convertMapToDataArguments, hexStringToAddress, queryResultValueToHex, queryResultValueToString, hexToString } from '../lib'
import { Contract, parseQueryResult } from '../contract'

const ESDT_TRANSFER_METHOD = 'ESDTTransfer'

/**
* Parse token info result.
Expand Down Expand Up @@ -116,7 +117,7 @@ class TokenTransferBuilder extends TransactionBuilder {
}

public getTransactionDataString(): string {
return joinDataArguments(`ESDTTransfer`, stringToHex(this._tokenId), numberToHex(this._amount))
return joinDataArguments(ESDT_TRANSFER_METHOD, stringToHex(this._tokenId), numberToHex(this._amount))
}

public getReceiverAddress(): string {
Expand Down Expand Up @@ -198,20 +199,32 @@ export class Token extends TransactionOptionsBase {
value: TOKEN_CREATION_COST /* 5 eGLD */
})

await options.provider!.waitForTransaction(tx.hash)
const ret = await options.provider!.waitForTransaction(tx.hash)

// find out token id
const possibleIds = (await Token.getAllTokenIds(options)).reverse().filter(id => id.includes(`${ticker}-`))
let tokenId
try {
for (let result of ret.transactionOnChain!.smartContractResults) {
const { data } = result

if (data.startsWith(ESDT_TRANSFER_METHOD)) {
const toks = data.split(ARGS_DELIMITER)
tokenId = hexToString(toks[1])
if (!tokenId) {
throw new Error('Id not found in transfer result')
}
break
}
}

for (let id of possibleIds) {
const t = new Token(id, c, options)
const info = await t.getInfo()
if (info.name === name && info.supply.eq(initialSupply) && info.owner === options.sender) {
return t
if (!tokenId) {
throw new Error('Transfer result not found')
}
} catch (err) {
throw new Error(`Unable to extract token id: ${err.message}`)
}

throw new Error(`Token created, but unable to retrieve token id`)
return new Token(tokenId, c, options)
}


Expand Down
2 changes: 1 addition & 1 deletion test/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe('query response parser', () => {
expect(parseQueryResult({
...baseResult,
returnData: [
'dHJ1ZQ==',
'AQ==',
]
}, {
type: ContractQueryResultDataType.BOOLEAN,
Expand Down