From 2b1a85b4ac7e9e68334d34aa37f733bf1ed589fe Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Wed, 5 Dec 2018 17:53:19 +0200 Subject: [PATCH] update async funcs --- src/index.ts | 86 ++++++++++++++++++++++++++-------------------------- src/trudy.ts | 8 ++--- yarn.lock | 2 +- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/index.ts b/src/index.ts index 88abd65..0e5aedc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ program "deposit the specified amount of LOOM tokens into the Transfer Gateway" ) .action(async function(amount: string) { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -27,7 +27,7 @@ program config.loomTokenEthAddress ); try { - const tx = await user.deposit(new BN(amount).mul(coinMultiplier)); + const tx = await user.depositAsync(new BN(amount).mul(coinMultiplier)); await tx.wait(); console.log(`${amount} tokens deposited to Ethereum Gateway.`); console.log(`Rinkeby tx hash: ${tx.hash}`); @@ -46,37 +46,36 @@ program "Number of seconds to wait for withdrawal to be processed" ) .action(async function(amount: string, options: any) { - let user + let user; try { - user = await DPOSUser.createOfflineUser( - config.ethEndpoint, - config.ethPrivateKey, - config.dappchainEndpoint, - config.dappchainPrivateKey, - config.chainId, - config.loomGatewayEthAddress, - config.loomTokenEthAddress - ); + user = await DPOSUser.createOfflineUserAsync( + config.ethEndpoint, + config.ethPrivateKey, + config.dappchainEndpoint, + config.dappchainPrivateKey, + config.chainId, + config.loomGatewayEthAddress, + config.loomTokenEthAddress + ); const actualAmount = new BN(amount).mul(coinMultiplier); - const tx = await user.withdraw(actualAmount) + const tx = await user.withdrawAsync(actualAmount); await tx.wait(); console.log(`${amount} tokens withdrawn from Ethereum Gateway.`); console.log(`Rinkeby tx hash: ${tx.hash}`); } catch (err) { console.error(err); } finally { - if (user) - user.disconnect() + if (user) user.disconnect(); } }); program .command("resume-withdrawal") .description("Resumes a withdrawal from a pending receipt") - .action(async function () { + .action(async function() { let user; try { - user = await DPOSUser.createOfflineUser( + user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -85,7 +84,7 @@ program config.loomGatewayEthAddress, config.loomTokenEthAddress ); - const tx = await user.resumeWithdrawal() + const tx = await user.resumeWithdrawalAsync(); if (tx) { await tx.wait(); } @@ -102,7 +101,7 @@ program .command("receipt") .description("Returns the currently pending receipt") .action(async function() { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -112,7 +111,7 @@ program config.loomTokenEthAddress ); try { - const receipt = await user.getPendingWithdrawalReceipt(); + const receipt = await user.getPendingWithdrawalReceiptAsync(); if (receipt) { console.log(`Pending receipt:`); console.log("Token owner:", receipt.tokenOwner.toString()); @@ -137,7 +136,7 @@ program .command("list-validators") .description("Show the current DPoS validators") .action(async function() { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -147,7 +146,7 @@ program config.loomTokenEthAddress ); try { - const validators = await user.listValidators(); + const validators = await user.listValidatorsAsync(); console.log(`Current validators:`); validators.forEach(v => { console.log(" Pubkey:", CryptoUtils.Uint8ArrayToB64(v.pubKey)); @@ -166,7 +165,7 @@ program .command("list-candidates") .description("Show the current DPoS candidates (along with their metadata)") .action(async function() { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -176,7 +175,7 @@ program config.loomTokenEthAddress ); try { - const candidates = await user.listCandidates(); + const candidates = await user.listCandidatesAsync(); console.log(`Current candidates:`); candidates.forEach(c => { console.log(" Pubkey:", CryptoUtils.Uint8ArrayToB64(c.pubKey)); @@ -199,7 +198,7 @@ program .option("-v, --validator ") .option("-d, --delegator ") .action(async function(option) { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -209,7 +208,8 @@ program config.loomTokenEthAddress ); try { - const delegation = await user.checkDelegations( + console.log(option.validator, option.delegator); + const delegation = await user.checkDelegationsAsync( option.validator, option.delegator ); @@ -227,7 +227,7 @@ program .description("Get back the user rewards") .option("-a, --account ") .action(async function() { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -237,7 +237,7 @@ program config.loomTokenEthAddress ); try { - const rewards = await user.claimDelegations(); + const rewards = await user.claimDelegationsAsync(); console.log(`User claimed back rewards: ${rewards}`); } catch (err) { console.error(err); @@ -248,7 +248,7 @@ program .command("delegate ") .description("Delegate `amount` to a candidate / validator") .action(async function(amount: string, validator: string) { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -260,7 +260,7 @@ program try { const actualAmount = new BN(amount).mul(coinMultiplier); console.log(`Delegating ${actualAmount.toString()} to validator`); - await user.delegate(validator, actualAmount); + await user.delegateAsync(validator, actualAmount); console.log(`Delegated ${actualAmount.toString()} to validator`); } catch (err) { console.error(err); @@ -271,7 +271,7 @@ program .command("undelegate ") .option("-v, --validator ") .action(async function(amount: string, validator: string) { - const user = await DPOSUser.createOfflineUser( + const user = await DPOSUser.createOfflineUserAsync( config.ethEndpoint, config.ethPrivateKey, config.dappchainEndpoint, @@ -281,7 +281,7 @@ program config.loomTokenEthAddress ); try { - await user.undelegate(validator, new BN(amount).mul(coinMultiplier)); + await user.undelegateAsync(validator, new BN(amount).mul(coinMultiplier)); console.log(`Undelegated ${amount} LOOM to ${validator}`); } catch (err) { console.error(err); @@ -302,17 +302,17 @@ program ) .action(async function(options) { try { - const user = await DPOSUser.createOfflineUser( - config.ethEndpoint, - config.ethPrivateKey, - config.dappchainEndpoint, - config.dappchainPrivateKey, - config.chainId, - config.loomGatewayEthAddress, - config.loomTokenEthAddress - ); - const balance = await user.getDAppChainBalance(options.account); - console.log(`The account's balance is ${balance}`); + const user = await DPOSUser.createOfflineUserAsync( + config.ethEndpoint, + config.ethPrivateKey, + config.dappchainEndpoint, + config.dappchainPrivateKey, + config.chainId, + config.loomGatewayEthAddress, + config.loomTokenEthAddress + ); + const balance = await user.getDAppChainBalanceAsync(options.account); + console.log(`The account's balance is ${balance}`); } catch (err) { console.error(err); } diff --git a/src/trudy.ts b/src/trudy.ts index 8f972e4..1ae6c5c 100644 --- a/src/trudy.ts +++ b/src/trudy.ts @@ -4,8 +4,8 @@ export const config = { ethEndpoint: "https://rinkeby.infura.io", dappchainPrivateKey: "OED7hbGxMW3xzlRM7JLRyRRvlEJ6wUCG/A6VEpngIyeoXMHT2YqfxHZuKSd8WIx6Dre5PyYXss2qv8rp2PaXuA==", - dappchainEndpoint: "http://loomv2a.dappchains.com:46658", - loomTokenEthAddress: "0x3666963A2fD915C9FcCC4A8285139b76Ca3b36cd", - loomGatewayEthAddress: "0x41B101f10528F58bd602e83Ea32431858177D1C5", - chainId: "loomv2a" + dappchainEndpoint: "https://test-z-asia1.dappchains.com", + loomTokenEthAddress: "0x97D24aCf088BBA06dB8b3675eF17bC02077CbDFa", + loomGatewayEthAddress: "0xd242754d9D02f46D4e33B0eDaff04099A0A346aF", + chainId: "asia1" }; diff --git a/yarn.lock b/yarn.lock index 0af06c0..0966c44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4975,7 +4975,7 @@ log-update@^1.0.2: "loom-js@https://github.com/loomnetwork/loom-js#build-files": version "1.34.0" - resolved "https://github.com/loomnetwork/loom-js#523e8c9a04612f5f49293b711fd86a2571f1aec4" + resolved "https://github.com/loomnetwork/loom-js#eca8fe73167fa25da385660cf318f39d20fa49cc" dependencies: abi-decoder "^1.2.0" axios "^0.18.0"