chore(core):added sendRawStakingTransaction to blockchain

datastructure-update
neeboo 5 years ago
parent 1e63f5a465
commit bb13a3bff0
  1. 1
      packages/harmony-core/package.json
  2. 27
      packages/harmony-core/src/blockchain.ts
  3. 2
      packages/harmony-core/src/harmony.ts
  4. 23
      packages/harmony-staking/src/stakingTransaction.ts

@ -22,6 +22,7 @@
"@harmony-js/contract": "0.1.30",
"@harmony-js/crypto": "0.1.28",
"@harmony-js/network": "0.1.29",
"@harmony-js/staking": "^0.1.29",
"@harmony-js/transaction": "0.1.30",
"@harmony-js/utils": "0.1.28"
},

@ -19,6 +19,7 @@ import {
import { getAddress } from '@harmony-js/crypto';
import { Transaction } from '@harmony-js/transaction';
import { StakingTransaction } from '@harmony-js/staking';
class Blockchain {
messenger: Messenger;
@ -394,7 +395,7 @@ class Blockchain {
throw new Error('transaction is not signed or not exist');
}
const [txn, result] = await transaction.sendTransaction();
if (txn.isPending) {
if (txn.isPending()) {
return result;
}
}
@ -414,6 +415,30 @@ class Blockchain {
}
}
async sendRawStakingTransaction(staking: StakingTransaction) {
if (!staking.isSigned() || !staking) {
throw new Error('staking transaction is not signed or not exist');
}
const [txn, result] = await staking.sendTransaction();
if (txn.isPending()) {
return result;
}
}
createObservedStakingTransaction(staking: StakingTransaction) {
try {
staking.sendTransaction().then((response: any) => {
const [txReturned, TranID] = response;
txReturned.confirm(TranID).then((txConfirmed: StakingTransaction) => {
staking.emitter.resolve(txConfirmed);
});
});
return staking.emitter;
} catch (err) {
throw err;
}
}
@assertObject({
to: ['isValidAddress', AssertType.optional],
data: ['isHex', AssertType.optional],

@ -3,6 +3,7 @@ import * as utils from '@harmony-js/utils';
import { Provider, HttpProvider, Messenger, WSProvider, ShardingItem } from '@harmony-js/network';
import { TransactionFactory, Transaction } from '@harmony-js/transaction';
import { StakingTransaction } from '@harmony-js/staking';
import { ContractFactory, Contract } from '@harmony-js/contract';
import { Wallet, Account } from '@harmony-js/account';
import { Blockchain } from './blockchain';
@ -17,6 +18,7 @@ export class Harmony extends utils.HarmonyCore {
TransactionFactory,
Wallet,
Transaction,
StakingTransaction,
Account,
Contract,
};

@ -115,7 +115,7 @@ export class StakingTransaction extends TransactionBase {
return encode(raw);
}
async sendTransaction(): Promise<[StakingTransaction, string]> {
public async sendTransaction(): Promise<[StakingTransaction, string]> {
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) {
throw new Error('Transaction not signed');
}
@ -127,7 +127,8 @@ export class StakingTransaction extends TransactionBase {
RPCMethod.SendRawStakingTransaction,
this.rawTransaction,
this.messenger.chainType,
0, // Staking tx always sent to shard 0
this.messenger.currentShard,
// 0, // Staking tx always sent to shard 0
);
if (res.isResult()) {
@ -178,6 +179,24 @@ export class StakingTransaction extends TransactionBase {
getFromAddress() {
return this.from;
}
async confirm(
txHash: string,
maxAttempts: number = 20,
interval: number = 1000,
shardID: number | string = this.messenger.currentShard,
toShardID: number | string = 0,
) {
const txConfirmed = await this.txConfirm(txHash, maxAttempts, interval, shardID);
if (shardID === toShardID) {
return txConfirmed;
}
if (txConfirmed.isConfirmed()) {
const cxConfirmed = await this.cxConfirm(txHash, maxAttempts, interval, toShardID);
return cxConfirmed;
} else {
return txConfirmed;
}
}
}
export class Description {

Loading…
Cancel
Save