fixing nonce 0 issue, changing StakingTransaction constructor, updating examples

test
Ganesha Upadhyaya 5 years ago
parent aeb46de5a5
commit d1f465ee94
  1. 2
      examples/staking_create.js
  2. 9
      examples/staking_delegate.js
  3. 55
      examples/staking_transfer.js
  4. 9
      examples/staking_undelegate.js
  5. 15
      packages/harmony-staking/src/stakingTransaction.ts

@ -6,7 +6,7 @@ const {
Delegate,
Undelegate,
CollectRewards,
} = require('@harmony-js/staking');
} = require('../packages/harmony-staking');
const createMsg = CreateValidator({
validatorAddress: 'one1a0x3d6xpmr6f8wsyaxd9v36pytvp48zckswvv9',

@ -24,7 +24,7 @@ const harmony = new Harmony(
// surge welcome lion goose gate consider taste injury health march debris kick
// add privateKey to wallet
const private = 'fd416cb87dcf8ed187e85545d7734a192fc8e976f5b540e9e21e896ec2bc25c3';
const private = '63e35b761e9df0d50ddcdaa8e33c235b60c991bfed22925a12768b0c08ef822f';
// one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy
const sender = harmony.wallet.addByPrivateKey(private);
console.log(sender.address);
@ -41,7 +41,7 @@ console.log(sender.address);
// '0xf8f180f8a4940b585f8daefbc68a311fbd4cb20d9174ad174016f83885416c69636585616c69636591616c6963652e6861726d6f6e792e6f6e6583426f6295446f6e2774206d6573732077697468206d65212121ddc988016345785d8a0000c9880c7d713b49da0000c887b1a2bc2ec500000a820bb8f1b0b9486167ab9087ab818dc4ce026edb5bf216863364c32e42df2af03c5ced1ad181e7d12f0e6dd5307a73b6224760861164008080830927c028a064b1b835f5b70a72228920db24e44c0a57d954c1d3dcac3b33c79d9593f96191a05577fd05064a37043a33ff7febb67ab126a8e1f0b67c92b7cab793a87ddf2c82';
const delegateMsg = new Delegate(
'one12fuf7x9rgtdgqg7vgq0962c556m3p7afsxgvll', // from delegate command.
'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp', // from delegate command.
'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy', // fd416cb87dcf8ed187e85545d7734a192fc8e976f5b540e9e21e896ec2bc25c3
'0xde0b6b3a7640000', // 0x56BC75E2D63100000
);
@ -54,10 +54,7 @@ const stakingTxn = new StakingTransaction(
'0x2',
'0x',
'0x0927c0',
2,
2,
'',
'',
ChainID.HmyLocal,
);
// 3. get sharding info

@ -6,7 +6,7 @@ const {
CommissionRate,
StakingTransaction,
CreateValidator,
} = require('@harmony-js/staking'); //../packages/harmony-staking
} = require('../packages/harmony-staking'); //../packages/harmony-staking
const { TxStatus } = require('@harmony-js/transaction');
const LOCALNET = `http://localhost:9500`;
@ -41,9 +41,7 @@ const sender = harmony.wallet.addByPrivateKey(private);
// add privateKey to wallet
// const sender = harmony.wallet.addByMnemonic(phrase);
let r =
'0xf8f180f8a4940b585f8daefbc68a311fbd4cb20d9174ad174016f83885416c69636585616c69636591616c6963652e6861726d6f6e792e6f6e6583426f6295446f6e2774206d6573732077697468206d65212121ddc988016345785d8a0000c9880c7d713b49da0000c887b1a2bc2ec500000a820bb8f1b0b9486167ab9087ab818dc4ce026edb5bf216863364c32e42df2af03c5ced1ad181e7d12f0e6dd5307a73b6224760861164008080830927c028a064b1b835f5b70a72228920db24e44c0a57d954c1d3dcac3b33c79d9593f96191a05577fd05064a37043a33ff7febb67ab126a8e1f0b67c92b7cab793a87ddf2c82';
// console.log(decode(r));
const desc = new Description('Alice', 'alice', 'alice.harmony.one', 'Bob', "Don't mess with me!!!");
const rate = new Decimal('0.1');
@ -63,7 +61,14 @@ const createMsg = new CreateValidator(
'0x56BC75E2D63100000', // 0x56BC75E2D63100000
);
const stakingTxn = new StakingTransaction('0x', createMsg, '0x2', '0x', '0x0927c0', 2, 2, '', '');
const stakingTxn = new StakingTransaction(
'0x',
createMsg,
'0x2',
'0x',
'0x0927c0',
ChainID.HmyLocal,
);
// 3. get sharding info
async function setSharding() {
@ -111,32 +116,32 @@ async function execute() {
// console.log(signedTxn);
// const [sentTxn, txnHash] = await signedTxn.sendTransaction();
signedTxn
.sendTransaction()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
const [sentTxn, txnHash] = await signedTxn.sendTransaction();
// signedTxn
// .sendTransaction()
// .then((res) => {
// console.log(res);
// })
// .catch((err) => {
// console.log(err);
// });
// to confirm the result if it is already there
// console.log(txnHash);
// console.log(sentTxn);
console.log(txnHash);
console.log(sentTxn);
// const confiremdTxn = await sentTxn.confirm(txnHash);
const confiremdTxn = await sentTxn.confirm(txnHash);
// if the transactino is cross-shard transaction
// if (!confiremdTxn.isCrossShard()) {
// if (confiremdTxn.isConfirmed()) {
// console.log('--- Result ---');
// console.log('');
// console.log('Normal transaction');
// console.log(`${txnHash} is confirmed`);
// console.log('');
// process.exit();
// }
if (confiremdTxn.isConfirmed()) {
console.log('--- Result ---');
console.log('');
console.log('Staking transaction');
console.log(`${txnHash} is confirmed`);
console.log('');
process.exit();
}
// }
// if (confiremdTxn.isConfirmed() && confiremdTxn.isCxConfirmed()) {
// console.log('--- Result ---');

@ -24,7 +24,7 @@ const harmony = new Harmony(
// surge welcome lion goose gate consider taste injury health march debris kick
// add privateKey to wallet
const private = 'fd416cb87dcf8ed187e85545d7734a192fc8e976f5b540e9e21e896ec2bc25c3';
const private = '63e35b761e9df0d50ddcdaa8e33c235b60c991bfed22925a12768b0c08ef822f';
const sender = harmony.wallet.addByPrivateKey(private);
// const phrase =
// 'genius cable radar memory high catch blossom correct middle wish gentle
@ -39,7 +39,7 @@ const sender = harmony.wallet.addByPrivateKey(private);
// '0xf8f180f8a4940b585f8daefbc68a311fbd4cb20d9174ad174016f83885416c69636585616c69636591616c6963652e6861726d6f6e792e6f6e6583426f6295446f6e2774206d6573732077697468206d65212121ddc988016345785d8a0000c9880c7d713b49da0000c887b1a2bc2ec500000a820bb8f1b0b9486167ab9087ab818dc4ce026edb5bf216863364c32e42df2af03c5ced1ad181e7d12f0e6dd5307a73b6224760861164008080830927c028a064b1b835f5b70a72228920db24e44c0a57d954c1d3dcac3b33c79d9593f96191a05577fd05064a37043a33ff7febb67ab126a8e1f0b67c92b7cab793a87ddf2c82';
const undelegateMsg = new Undelegate(
'one12fuf7x9rgtdgqg7vgq0962c556m3p7afsxgvll',
'one1pf75h0t4am90z8uv3y0dgunfqp4lj8wr3t5rsp', // signed should match this
'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy',
'0x16345785d8a0000',
);
@ -50,10 +50,7 @@ const stakingTxn = new StakingTransaction(
'0x2',
'0x',
'0x0927c0',
2,
2,
'',
'',
ChainID.HmyLocal,
);
// 3. get sharding info

@ -48,9 +48,6 @@ export class StakingTransaction extends TransactionBase {
gasPrice: number | string,
gasLimit: number | string,
chainID: number,
v: number,
r: string,
s: string,
messenger: Messenger = defaultMessenger,
txStatus = TxStatus.INTIALIZED,
) {
@ -64,10 +61,10 @@ export class StakingTransaction extends TransactionBase {
this.rawTransaction = '0x';
this.unsignedRawTransaction = '0x';
this.signature = {
r,
s,
r: '',
s: '',
recoveryParam: 0,
v,
v: 0,
};
this.chainId = chainID;
this.from = '0x';
@ -82,7 +79,11 @@ export class StakingTransaction extends TransactionBase {
raw.push(hexlify(this.directive));
}
raw.push(this.stakeMsg.encode());
raw.push(hexlify(this.nonce));
if (!this.nonce) {
raw.push('0x');
} else {
raw.push(hexlify(this.nonce));
}
raw.push(hexlify(this.gasPrice));
raw.push(hexlify(this.gasLimit));
if (this.chainId != null && this.chainId !== 0) {

Loading…
Cancel
Save