feat(examples):use factory to make code human readable

test
neeboo 5 years ago
parent cc00c23e9a
commit 4995796682
  1. 43
      examples/staking_delegate.js
  2. 44
      examples/staking_undelegate.js

@ -1,6 +1,6 @@
const { Harmony } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');
const { Delegate, StakingTransaction } = require('@harmony-js/staking'); //../packages/harmony-staking
const { Delegate, StakingTransaction, StakingFactory } = require('@harmony-js/staking'); //../packages/harmony-staking
const { TxStatus } = require('@harmony-js/transaction');
const LOCALNET = `http://localhost:9500`;
@ -40,22 +40,31 @@ console.log(sender.address);
// let r =
// '0xf8f180f8a4940b585f8daefbc68a311fbd4cb20d9174ad174016f83885416c69636585616c69636591616c6963652e6861726d6f6e792e6f6e6583426f6295446f6e2774206d6573732077697468206d65212121ddc988016345785d8a0000c9880c7d713b49da0000c887b1a2bc2ec500000a820bb8f1b0b9486167ab9087ab818dc4ce026edb5bf216863364c32e42df2af03c5ced1ad181e7d12f0e6dd5307a73b6224760861164008080830927c028a064b1b835f5b70a72228920db24e44c0a57d954c1d3dcac3b33c79d9593f96191a05577fd05064a37043a33ff7febb67ab126a8e1f0b67c92b7cab793a87ddf2c82';
const delegateMsg = new Delegate(
'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp', // from delegate command.
'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy', // fd416cb87dcf8ed187e85545d7734a192fc8e976f5b540e9e21e896ec2bc25c3
'0xde0b6b3a7640000', // 0x56BC75E2D63100000
);
// one12fuf7x9rgtdgqg7vgq0962c556m3p7afsxgvll;
const stakingTxn = new StakingTransaction(
'0x2',
delegateMsg,
'0x2',
'0x',
'0x0927c0',
ChainID.HmyLocal,
);
// const delegateMsg = new Delegate(
// 'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp', // from delegate command.
// 'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy', // fd416cb87dcf8ed187e85545d7734a192fc8e976f5b540e9e21e896ec2bc25c3
// '0xde0b6b3a7640000', // 0x56BC75E2D63100000
// );
// // one12fuf7x9rgtdgqg7vgq0962c556m3p7afsxgvll;
// const stakingTxn = new StakingTransaction(
// '0x2',
// delegateMsg,
// '0x2',
// '0x',
// '0x0927c0',
// ChainID.HmyLocal,
// );
const stakingTxn = new StakingFactory(harmony.messenger)
.delegate({
delegatorAddress: 'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp',
validatorAddress: 'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy',
amount: '0xde0b6b3a7640000',
})
.setTxParams({ nonce: '0x2', gasPrice: '0x', gasLimit: '0x0927c0', chainId: ChainID.HmyLocal })
.build();
// 3. get sharding info
async function setSharding() {

@ -1,6 +1,6 @@
const { Harmony } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');
const { Undelegate, StakingTransaction } = require('@harmony-js/staking'); //../packages/harmony-staking
const { Undelegate, StakingTransaction, StakingFactory } = require('@harmony-js/staking'); //../packages/harmony-staking
const { TxStatus } = require('@harmony-js/transaction');
const LOCALNET = `http://localhost:9500`;
@ -38,20 +38,34 @@ const sender = harmony.wallet.addByPrivateKey(private);
// let r =
// '0xf8f180f8a4940b585f8daefbc68a311fbd4cb20d9174ad174016f83885416c69636585616c69636591616c6963652e6861726d6f6e792e6f6e6583426f6295446f6e2774206d6573732077697468206d65212121ddc988016345785d8a0000c9880c7d713b49da0000c887b1a2bc2ec500000a820bb8f1b0b9486167ab9087ab818dc4ce026edb5bf216863364c32e42df2af03c5ced1ad181e7d12f0e6dd5307a73b6224760861164008080830927c028a064b1b835f5b70a72228920db24e44c0a57d954c1d3dcac3b33c79d9593f96191a05577fd05064a37043a33ff7febb67ab126a8e1f0b67c92b7cab793a87ddf2c82';
const undelegateMsg = new Undelegate(
'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp', // signed should match this
'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy',
'0x16345785d8a0000',
);
const stakingTxn = new StakingTransaction(
'0x3',
undelegateMsg,
'0x2',
'0x',
'0x0927c0',
ChainID.HmyLocal,
);
// const undelegateMsg = new Undelegate(
// 'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp', // signed should match this
// 'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy',
// '0x16345785d8a0000',
// );
// const stakingTxn = new StakingTransaction(
// '0x3',
// undelegateMsg,
// '0x2',
// '0x',
// '0x0927c0',
// ChainID.HmyLocal,
// );
const stakingTxn = new StakingFactory(harmony.messenger)
.undelegate({
delegatorAddress: 'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp',
validatorAddress: 'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy',
amount: '0x16345785d8a0000',
})
.setTxParams({
nonce: '0x2',
gasPrice: '0x',
gasLimit: '0x0927c0',
chainId: ChainID.HmyLocal,
})
.build();
// 3. get sharding info
async function setSharding() {

Loading…
Cancel
Save