Skip to content

Commit

Permalink
added getAccountBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Jan 13, 2021
1 parent 0111700 commit 5391a79
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/chain/tezos/contracts/tzip12/FA2Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {KeyStore, Signer} from '../../../../types/ExternalInterfaces';
import {TezosNodeWriter} from '../../TezosNodeWriter';
import {TezosParameterFormat} from '../../../../types/tezos/TezosChainTypes';
import {TezosNodeReader} from '../../TezosNodeReader';
import {TezosMessageUtils} from 'chain/tezos/TezosMessageUtil';

export interface Storage {
admin: string;
Expand Down Expand Up @@ -84,6 +85,16 @@ export namespace FA2Helper {
};
}

export async function getAccountBalance(server: string, mapid: number, account: string): Promise<number> {
const packedKey = TezosMessageUtils.encodeBigMapKey(Buffer.from(TezosMessageUtils.writePackedData(account, 'address'), 'hex'));
const mapResult = await TezosNodeReader.getValueForBigMapKey(server, mapid, packedKey);

if (mapResult === undefined)
throw new Error(`Map ${mapid} does not contain a record for ${account}`);
const jsonresult = JSONPath({ path: '$.int', json: mapResult });
return Number(jsonresult[0]);
}

export async function Mint(server: string, address: string, signer: Signer, keystore: KeyStore, amount: number, fee: number, mints: MintPair[], freight: number, gas: number): Promise<string> {
const entrypoint = `mint`;
let parameters: string = `[ ${mints.map(m => MintPairMicheline(m)).join(',')} ]`;
Expand Down

0 comments on commit 5391a79

Please sign in to comment.