Merge remote-tracking branch 'origin/master'

pull/64/head
lixp 4 years ago
commit 1b977860ad
  1. 6
      examples/package-lock.json
  2. 81
      packages/harmony-account/src/account.ts
  3. 4
      packages/harmony-account/src/hdnode.ts
  4. 2
      packages/harmony-core/src/harmonyExtension.ts
  5. 20
      packages/harmony-crypto/package-lock.json
  6. 2
      packages/harmony-network/src/rpcMethod/rpc.ts
  7. 54
      packages/harmony-staking/package-lock.json
  8. 25
      packages/harmony-staking/test/testSign.test.ts
  9. 42
      packages/harmony-transaction/package-lock.json
  10. 5
      packages/harmony-transaction/test/testSend.test.ts

@ -274,9 +274,9 @@
}
},
"elliptic": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz",
"integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==",
"version": "6.5.3",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
"integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
"requires": {
"bn.js": "^4.4.0",
"brorand": "^1.0.1",

@ -299,30 +299,18 @@ class Account {
if (updateNonce) {
// await this.updateBalances(blockNumber);
const txShardID = transaction.txParams.shardID;
const shardBalanceObject = await this.getShardBalance(
const shardNonce = await this.getShardNonce(
typeof txShardID === 'string' ? Number.parseInt(txShardID, 10) : txShardID,
blockNumber,
);
if (shardBalanceObject !== undefined) {
const shardNonce = shardBalanceObject.nonce;
transaction.setParams({
...transaction.txParams,
from:
this.messenger.chainPrefix === ChainType.Harmony
? this.bech32Address
: this.checksumAddress || '0x',
nonce: shardNonce,
});
} else {
transaction.setParams({
...transaction.txParams,
from:
this.messenger.chainPrefix === ChainType.Harmony
? this.bech32Address
: this.checksumAddress || '0x',
nonce: 0,
});
}
transaction.setParams({
...transaction.txParams,
from:
this.messenger.chainPrefix === ChainType.Harmony
? this.bech32Address
: this.checksumAddress || '0x',
nonce: shardNonce,
});
}
if (encodeMode === 'rlp') {
@ -370,27 +358,16 @@ class Account {
if (updateNonce) {
// await this.updateBalances(blockNumber);
const txShardID = shardID;
const shardBalanceObject = await this.getShardBalance(
const shardNonce = await this.getShardNonce(
typeof txShardID === 'string' ? Number.parseInt(txShardID, 10) : txShardID,
blockNumber,
);
if (shardBalanceObject !== undefined) {
const shardNonce = shardBalanceObject.nonce;
staking.setFromAddress(
this.messenger.chainPrefix === ChainType.Harmony
? this.bech32Address
: this.checksumAddress || '0x',
);
staking.setNonce(shardNonce);
} else {
staking.setFromAddress(
this.messenger.chainPrefix === ChainType.Harmony
? this.bech32Address
: this.checksumAddress || '0x',
);
staking.setNonce(0);
}
staking.setFromAddress(
this.messenger.chainPrefix === ChainType.Harmony
? this.bech32Address
: this.checksumAddress || '0x',
);
staking.setNonce(shardNonce);
}
if (encodeMode === 'rlp') {
@ -510,6 +487,32 @@ class Account {
};
}
/**
* Get the specific shard's nonce
*
* @param shardID `shardID` is binding with the endpoint, IGNORE it!
* @param blockNumber by default, it's `latest`
*
* @example
* ```
* account.getShardNonce().then((value) => {
* console.log(value);
* });
* ```
*/
async getShardNonce(shardID: number, blockNumber: string = 'latest') {
const nonce = await this.messenger.send(
RPCMethod.GetAccountNonce,
[this.address, blockNumber],
this.messenger.chainPrefix,
shardID,
);
if (nonce.isError()) {
throw nonce.error.message;
}
return Number.parseInt(hexToNumber(nonce.result), 10);
}
/**
* @function _new private method create Account
* @return {Account} Account instance

@ -15,7 +15,7 @@ import {
isHex,
hexToNumber,
} from '@harmony-js/utils';
import { Messenger, HttpProvider, WSProvider } from '@harmony-js/network';
import { Messenger, HttpProvider, WSProvider, RPCMethod } from '@harmony-js/network';
import { Transaction, TxStatus, TransasctionReceipt } from '@harmony-js/transaction';
import { Account } from './account';
@ -170,7 +170,7 @@ export class HDNode {
async signTransaction(txParams: any | Web3TxPrams) {
const from: string = txParams.from ? getAddress(txParams.from).checksum : '0x';
const accountNonce = await this.messenger.send(
'hmy_getTransactionCount',
RPCMethod.GetAccountNonce,
[from, 'latest'],
'hmy',
this.shardID,

@ -172,7 +172,7 @@ export class HarmonyExtension {
if (updateNonce) {
const nonce = await this.messenger.send(
RPCMethod.GetTransactionCount,
RPCMethod.GetAccountNonce,
[crypto.getAddress(extensionAccount.address).checksum, blockNumber],
this.messenger.chainPrefix,
typeof transaction.txParams.shardID === 'string'

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@harmony-js/utils": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/utils/-/utils-0.1.54.tgz",
"integrity": "sha512-+LzQrcOoNqi+ehcElXQABHUXyJl9XXkLWUn9oghYLctwRuF4xHmsyzOa5cNLzAuxuK/j/VfPHT4jZ+banevZjw==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/utils/-/utils-0.1.55.tgz",
"integrity": "sha512-CnV7I+eotS12JyV6jdkuP8Pz19o2utUKCiAN0r0ba+vWs1O59V7vPDUjPSFlxNEujQQGm6pby+JQVL8QZqytOg==",
"requires": {
"@types/bn.js": "^4.11.3",
"bn.js": "^4.11.8"
@ -22,9 +22,9 @@
}
},
"@types/node": {
"version": "14.6.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.4.tgz",
"integrity": "sha512-Wk7nG1JSaMfMpoMJDKUsWYugliB2Vy55pdjLpmLixeyMi7HizW2I/9QoxsPCkXl3dO+ZOVqPumKaDUv5zJu2uQ=="
"version": "14.11.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.2.tgz",
"integrity": "sha512-jiE3QIxJ8JLNcb1Ps6rDbysDhN4xa8DJJvuC9prr6w+1tIh+QAbYyNF3tyiZNLDBIuBCf4KEcV2UvQm/V60xfA=="
},
"aes-js": {
"version": "3.1.2",
@ -158,9 +158,9 @@
}
},
"elliptic": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz",
"integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==",
"version": "6.5.3",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
"integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
"requires": {
"bn.js": "^4.4.0",
"brorand": "^1.0.1",
@ -304,7 +304,7 @@
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
},
"scrypt-shim": {
"version": "github:web3-js/scrypt-shim#be5e616323a8b5e568788bf94d03c1b8410eac54",
"version": "github:web3-js/scrypt-shim#aafdadda13e660e25e1c525d1f5b2443f5eb1ebb",
"from": "github:web3-js/scrypt-shim",
"requires": {
"scryptsy": "^2.1.0",

@ -95,6 +95,8 @@ export enum RPCMethod {
GetShardingStructure = 'hmy_getShardingStructure',
// 33. hmy_sendRawStakingTransaction
SendRawStakingTransaction = 'hmy_sendRawStakingTransaction',
// 34. hmy_getAccountNonce
GetAccountNonce = 'hmy_getAccountNonce',
}
/**@ignore */

@ -5,11 +5,11 @@
"requires": true,
"dependencies": {
"@harmony-js/crypto": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/crypto/-/crypto-0.1.54.tgz",
"integrity": "sha512-JfrHT84x7BN9alE+Oe3OJruUZrEE1ZjbaWCuRb2YuZbSRuHoS1h240eJ2jgoiOTUU7oS886Kwfai4IXB0mhTtA==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/crypto/-/crypto-0.1.55.tgz",
"integrity": "sha512-Gpp6eGkhmdqz86uoYwE1d3pqVbpNkUQlO51ufjb8lzWVFt5N8t3tj14xVycU+TI1bioikWaFd0xsJfPlCo79nA==",
"requires": {
"@harmony-js/utils": "0.1.54",
"@harmony-js/utils": "0.1.55",
"aes-js": "^3.1.2",
"bip39": "^2.5.0",
"bn.js": "^4.11.8",
@ -23,30 +23,30 @@
}
},
"@harmony-js/network": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/network/-/network-0.1.54.tgz",
"integrity": "sha512-ONw8JFVR7DMrsuwVf/OgTeafNTRAc9S4jsgWZg/L61gTDJNKuFtf/wq5wgcgxgVMeoQIkK17tm49qFCye//H7g==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/network/-/network-0.1.55.tgz",
"integrity": "sha512-8Utx0tC7gjqF2Ipzibfze72KxxNBdMOPZipeqxDBbFJf9q8iK3G9i21fFIIZiwgBhoTsJ/Sn6BNDEv0E80yiaA==",
"requires": {
"@harmony-js/utils": "0.1.54",
"@harmony-js/utils": "0.1.55",
"cross-fetch": "^3.0.2",
"mitt": "^1.2.0",
"websocket": "^1.0.28"
}
},
"@harmony-js/transaction": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/transaction/-/transaction-0.1.54.tgz",
"integrity": "sha512-J9CofH9HlSk9YPCS32c+lo6aurhA93+T7xBFL+HnnpWiBwvmZBFm7xrrbaNkDkSM9r6+pYnOzv/O7kiS8tXVmg==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/transaction/-/transaction-0.1.55.tgz",
"integrity": "sha512-kLrVON17lzj/aZR6kOJDKHwwFjKsaQtmD/DSG/WAVpgxh04B/NL0XsDUK/RD6hy6tHd04Pt+f47GNqcv7ZsrYA==",
"requires": {
"@harmony-js/crypto": "0.1.54",
"@harmony-js/network": "0.1.54",
"@harmony-js/utils": "0.1.54"
"@harmony-js/crypto": "0.1.55",
"@harmony-js/network": "0.1.55",
"@harmony-js/utils": "0.1.55"
}
},
"@harmony-js/utils": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/utils/-/utils-0.1.54.tgz",
"integrity": "sha512-+LzQrcOoNqi+ehcElXQABHUXyJl9XXkLWUn9oghYLctwRuF4xHmsyzOa5cNLzAuxuK/j/VfPHT4jZ+banevZjw==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/utils/-/utils-0.1.55.tgz",
"integrity": "sha512-CnV7I+eotS12JyV6jdkuP8Pz19o2utUKCiAN0r0ba+vWs1O59V7vPDUjPSFlxNEujQQGm6pby+JQVL8QZqytOg==",
"requires": {
"@types/bn.js": "^4.11.3",
"bn.js": "^4.11.8"
@ -61,9 +61,9 @@
}
},
"@types/node": {
"version": "14.6.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.4.tgz",
"integrity": "sha512-Wk7nG1JSaMfMpoMJDKUsWYugliB2Vy55pdjLpmLixeyMi7HizW2I/9QoxsPCkXl3dO+ZOVqPumKaDUv5zJu2uQ=="
"version": "14.11.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.2.tgz",
"integrity": "sha512-jiE3QIxJ8JLNcb1Ps6rDbysDhN4xa8DJJvuC9prr6w+1tIh+QAbYyNF3tyiZNLDBIuBCf4KEcV2UvQm/V60xfA=="
},
"aes-js": {
"version": "3.1.2",
@ -195,11 +195,11 @@
}
},
"cross-fetch": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.5.tgz",
"integrity": "sha512-FFLcLtraisj5eteosnX1gf01qYDCOc4fDy0+euOt8Kn9YBY2NtXL/pCoYPavw24NIQkQqm5ZOLsGD5Zzj0gyew==",
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz",
"integrity": "sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==",
"requires": {
"node-fetch": "2.6.0"
"node-fetch": "2.6.1"
}
},
"d": {
@ -396,9 +396,9 @@
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"node-gyp-build": {
"version": "3.7.0",

@ -319,11 +319,6 @@ describe('test sign staking transaction', () => {
it('should test sign create validator staking transaction using wallet', async () => {
const testTx: any = testTransactions[0];
const responses = [
{
jsonrpc: '2.0',
id: 1,
result: '0x666666666666',
},
{
jsonrpc: '2.0',
id: 1,
@ -369,11 +364,6 @@ describe('test sign staking transaction', () => {
it('should test sign edit validator staking transaction using wallet', async () => {
const testTx: any = testTransactions[1];
const responses = [
{
jsonrpc: '2.0',
id: 1,
result: '0x666666666666',
},
{
jsonrpc: '2.0',
id: 1,
@ -414,11 +404,6 @@ describe('test sign staking transaction', () => {
it('should test sign delegate staking transaction using wallet', async () => {
const testTx: any = testTransactions[2];
const responses = [
{
jsonrpc: '2.0',
id: 1,
result: '0x666666666666',
},
{
jsonrpc: '2.0',
id: 1,
@ -450,11 +435,6 @@ describe('test sign staking transaction', () => {
const testTx: any = testTransactions[3];
const responses = [
{
jsonrpc: '2.0',
id: 1,
result: '0x666666666666',
},
{
jsonrpc: '2.0',
id: 1,
@ -487,11 +467,6 @@ describe('test sign staking transaction', () => {
it('should test sign collect rewards staking transaction using wallet', async () => {
const testTx: any = testTransactions[4];
const responses = [
{
jsonrpc: '2.0',
id: 1,
result: '0x666666666666',
},
{
jsonrpc: '2.0',
id: 1,

@ -5,11 +5,11 @@
"requires": true,
"dependencies": {
"@harmony-js/crypto": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/crypto/-/crypto-0.1.54.tgz",
"integrity": "sha512-JfrHT84x7BN9alE+Oe3OJruUZrEE1ZjbaWCuRb2YuZbSRuHoS1h240eJ2jgoiOTUU7oS886Kwfai4IXB0mhTtA==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/crypto/-/crypto-0.1.55.tgz",
"integrity": "sha512-Gpp6eGkhmdqz86uoYwE1d3pqVbpNkUQlO51ufjb8lzWVFt5N8t3tj14xVycU+TI1bioikWaFd0xsJfPlCo79nA==",
"requires": {
"@harmony-js/utils": "0.1.54",
"@harmony-js/utils": "0.1.55",
"aes-js": "^3.1.2",
"bip39": "^2.5.0",
"bn.js": "^4.11.8",
@ -23,20 +23,20 @@
}
},
"@harmony-js/network": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/network/-/network-0.1.54.tgz",
"integrity": "sha512-ONw8JFVR7DMrsuwVf/OgTeafNTRAc9S4jsgWZg/L61gTDJNKuFtf/wq5wgcgxgVMeoQIkK17tm49qFCye//H7g==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/network/-/network-0.1.55.tgz",
"integrity": "sha512-8Utx0tC7gjqF2Ipzibfze72KxxNBdMOPZipeqxDBbFJf9q8iK3G9i21fFIIZiwgBhoTsJ/Sn6BNDEv0E80yiaA==",
"requires": {
"@harmony-js/utils": "0.1.54",
"@harmony-js/utils": "0.1.55",
"cross-fetch": "^3.0.2",
"mitt": "^1.2.0",
"websocket": "^1.0.28"
}
},
"@harmony-js/utils": {
"version": "0.1.54",
"resolved": "https://registry.npmjs.org/@harmony-js/utils/-/utils-0.1.54.tgz",
"integrity": "sha512-+LzQrcOoNqi+ehcElXQABHUXyJl9XXkLWUn9oghYLctwRuF4xHmsyzOa5cNLzAuxuK/j/VfPHT4jZ+banevZjw==",
"version": "0.1.55",
"resolved": "https://registry.npmjs.org/@harmony-js/utils/-/utils-0.1.55.tgz",
"integrity": "sha512-CnV7I+eotS12JyV6jdkuP8Pz19o2utUKCiAN0r0ba+vWs1O59V7vPDUjPSFlxNEujQQGm6pby+JQVL8QZqytOg==",
"requires": {
"@types/bn.js": "^4.11.3",
"bn.js": "^4.11.8"
@ -51,9 +51,9 @@
}
},
"@types/node": {
"version": "14.6.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.4.tgz",
"integrity": "sha512-Wk7nG1JSaMfMpoMJDKUsWYugliB2Vy55pdjLpmLixeyMi7HizW2I/9QoxsPCkXl3dO+ZOVqPumKaDUv5zJu2uQ=="
"version": "14.11.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.11.2.tgz",
"integrity": "sha512-jiE3QIxJ8JLNcb1Ps6rDbysDhN4xa8DJJvuC9prr6w+1tIh+QAbYyNF3tyiZNLDBIuBCf4KEcV2UvQm/V60xfA=="
},
"aes-js": {
"version": "3.1.2",
@ -185,11 +185,11 @@
}
},
"cross-fetch": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.5.tgz",
"integrity": "sha512-FFLcLtraisj5eteosnX1gf01qYDCOc4fDy0+euOt8Kn9YBY2NtXL/pCoYPavw24NIQkQqm5ZOLsGD5Zzj0gyew==",
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz",
"integrity": "sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==",
"requires": {
"node-fetch": "2.6.0"
"node-fetch": "2.6.1"
}
},
"d": {
@ -386,9 +386,9 @@
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"node-gyp-build": {
"version": "3.7.0",

@ -34,11 +34,6 @@ describe('test send transaction', () => {
});
it('should test wallet sign and send', async () => {
const responses = [
{
jsonrpc: '2.0',
id: 1,
result: '0x666666666666',
},
{
jsonrpc: '2.0',
id: 1,

Loading…
Cancel
Save