Skip to content

Commit

Permalink
update async funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Dec 5, 2018
1 parent 3d6a08a commit 2b1a85b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
86 changes: 43 additions & 43 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}`);
Expand All @@ -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,
Expand All @@ -85,7 +84,7 @@ program
config.loomGatewayEthAddress,
config.loomTokenEthAddress
);
const tx = await user.resumeWithdrawal()
const tx = await user.resumeWithdrawalAsync();
if (tx) {
await tx.wait();
}
Expand All @@ -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,
Expand All @@ -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());
Expand All @@ -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,
Expand All @@ -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));
Expand All @@ -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,
Expand All @@ -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));
Expand All @@ -199,7 +198,7 @@ program
.option("-v, --validator <dappchain b64 address>")
.option("-d, --delegator <dappchain b64 address>")
.action(async function(option) {
const user = await DPOSUser.createOfflineUser(
const user = await DPOSUser.createOfflineUserAsync(
config.ethEndpoint,
config.ethPrivateKey,
config.dappchainEndpoint,
Expand All @@ -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
);
Expand All @@ -227,7 +227,7 @@ program
.description("Get back the user rewards")
.option("-a, --account <account to withdraw the rewards to>")
.action(async function() {
const user = await DPOSUser.createOfflineUser(
const user = await DPOSUser.createOfflineUserAsync(
config.ethEndpoint,
config.ethPrivateKey,
config.dappchainEndpoint,
Expand All @@ -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);
Expand All @@ -248,7 +248,7 @@ program
.command("delegate <amount> <validator>")
.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,
Expand All @@ -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);
Expand All @@ -271,7 +271,7 @@ program
.command("undelegate <amount> <validator>")
.option("-v, --validator <dappchain b64 address>")
.action(async function(amount: string, validator: string) {
const user = await DPOSUser.createOfflineUser(
const user = await DPOSUser.createOfflineUserAsync(
config.ethEndpoint,
config.ethPrivateKey,
config.dappchainEndpoint,
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/trudy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2b1a85b

Please sign in to comment.