@harmony-js/transaction
Advanced tools
Comparing version 0.1.7 to 0.1.12
@@ -9,3 +9,3 @@ import { Messenger } from '@harmony-js/network'; | ||
setMessenger(messenger: Messenger): void; | ||
newTx(txParams?: TxParams | any): Transaction; | ||
newTx(txParams?: TxParams | any, sharding?: boolean): Transaction; | ||
clone(transaction: Transaction): Transaction; | ||
@@ -12,0 +12,0 @@ recover(txHash: string): Transaction; |
@@ -5,2 +5,3 @@ "use strict"; | ||
var transaction_1 = require("./transaction"); | ||
var shardingTransaction_1 = require("./shardingTransaction"); | ||
var TransactionFactory = /** @class */ (function () { | ||
@@ -12,4 +13,3 @@ function TransactionFactory(messenger) { | ||
var _a = tx.txParams, from = _a.from, nonce = _a.nonce; | ||
return crypto_1.getAddress(crypto_1.getContractAddress(from, Number.parseInt("" + nonce, 10))) | ||
.checksum; | ||
return crypto_1.getAddress(crypto_1.getContractAddress(from, Number.parseInt("" + nonce, 10))).checksum; | ||
}; | ||
@@ -19,4 +19,8 @@ TransactionFactory.prototype.setMessenger = function (messenger) { | ||
}; | ||
TransactionFactory.prototype.newTx = function (txParams) { | ||
return new transaction_1.Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
TransactionFactory.prototype.newTx = function (txParams, sharding) { | ||
if (sharding === void 0) { sharding = false; } | ||
if (!sharding) { | ||
return new transaction_1.Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
} | ||
return new shardingTransaction_1.ShardingTransaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
}; | ||
@@ -23,0 +27,0 @@ TransactionFactory.prototype.clone = function (transaction) { |
@@ -27,3 +27,17 @@ /** | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
@@ -204,4 +218,3 @@ __assign = Object.assign || function __assign(t) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -283,4 +296,3 @@ catch (error) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -307,3 +319,3 @@ catch (error) { | ||
})(exports.TransactionEvents || (exports.TransactionEvents = {})); | ||
var defaultMessenger = new network.Messenger(new network.HttpProvider('http://localhost:8545'), "hmy" /* Harmony */); | ||
var defaultMessenger = new network.Messenger(new network.HttpProvider('http://localhost:9500'), "hmy" /* Harmony */); | ||
var RLPSign = function (transaction, prv) { | ||
@@ -535,3 +547,2 @@ var _a = __read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1]; | ||
case 0: | ||
// TODO: we use eth RPC setting for now, incase we have other params, we should add here | ||
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) { | ||
@@ -543,3 +554,3 @@ throw new Error('Transaction not signed'); | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction, this.messenger.chainType, typeof this.shardID === 'string' ? Number.parseInt(this.shardID, 10) : this.shardID)]; | ||
case 1: | ||
@@ -569,3 +580,4 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.trackTx = function (txHash) { | ||
Transaction.prototype.trackTx = function (txHash, shardID) { | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -579,3 +591,3 @@ var res, currentBlock, currentBlock; | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash, this.messenger.chainType, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)]; | ||
case 1: | ||
@@ -624,5 +636,6 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval) { | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval, shardID) { | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (interval === void 0) { interval = 1000; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -652,3 +665,3 @@ var oldBlock, checkBlock, attempt, newBlock, nextBlock, err_1, result, error_1; | ||
checkBlock = newBlock; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 5: | ||
@@ -686,3 +699,3 @@ if (_a.sent()) { | ||
_a.trys.push([13, 18, , 19]); | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 14: | ||
@@ -692,3 +705,3 @@ if (!_a.sent()) return [3 /*break*/, 15]; | ||
return [2 /*return*/, this]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts)]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts, shardID)]; | ||
case 16: | ||
@@ -708,7 +721,8 @@ result = _a.sent(); | ||
}; | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts) { | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts, shardID) { | ||
var _this = this; | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return new Promise(function (resolve, reject) { | ||
var newHeads = Promise.resolve(new network.NewHeaders(_this.messenger)); | ||
var newHeads = Promise.resolve(new network.NewHeaders(_this.messenger, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)); | ||
newHeads.then(function (p) { | ||
@@ -720,3 +734,3 @@ p.onData(function (data) { return __awaiter(_this, void 0, void 0, function () { | ||
if (!!this.blockNumbers.includes(data.params.result.number)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 1: | ||
@@ -832,2 +846,34 @@ if (!_a.sent()) return [3 /*break*/, 3]; | ||
var ShardingTransaction = /** @class */ (function (_super) { | ||
__extends(ShardingTransaction, _super); | ||
function ShardingTransaction(params, messenger, txStatus) { | ||
if (messenger === void 0) { messenger = defaultMessenger; } | ||
if (txStatus === void 0) { txStatus = "INITIALIZED" /* INTIALIZED */; } | ||
var _this = this; | ||
var fromAddress = params.from; | ||
var toAddress = params.to; | ||
var fromExtraction = fromAddress !== undefined ? fromAddress.split(utils.AddressSuffix) : ['0x', undefined]; | ||
var toExtraction = toAddress !== undefined ? toAddress.split(utils.AddressSuffix) : ['0x', undefined]; | ||
var from = fromExtraction[0]; | ||
var shardID = fromExtraction[1] !== undefined | ||
? Number.parseInt(fromExtraction[1], 10) | ||
: params.shardID !== undefined | ||
? params.shardID | ||
: 0; | ||
var to = toExtraction[0]; | ||
var toShardID = toExtraction[1] !== undefined | ||
? Number.parseInt(toExtraction[1], 10) | ||
: params.toShardID !== undefined | ||
? params.toShardID | ||
: 0; | ||
var reParams = __assign({}, params, { from: from, | ||
to: to, | ||
shardID: shardID, | ||
toShardID: toShardID }); | ||
_this = _super.call(this, reParams, messenger, txStatus) || this; | ||
return _this; | ||
} | ||
return ShardingTransaction; | ||
}(Transaction)); | ||
var TransactionFactory = /** @class */ (function () { | ||
@@ -839,4 +885,3 @@ function TransactionFactory(messenger) { | ||
var _a = tx.txParams, from = _a.from, nonce = _a.nonce; | ||
return crypto.getAddress(crypto.getContractAddress(from, Number.parseInt("" + nonce, 10))) | ||
.checksum; | ||
return crypto.getAddress(crypto.getContractAddress(from, Number.parseInt("" + nonce, 10))).checksum; | ||
}; | ||
@@ -846,4 +891,8 @@ TransactionFactory.prototype.setMessenger = function (messenger) { | ||
}; | ||
TransactionFactory.prototype.newTx = function (txParams) { | ||
return new Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
TransactionFactory.prototype.newTx = function (txParams, sharding) { | ||
if (sharding === void 0) { sharding = false; } | ||
if (!sharding) { | ||
return new Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
} | ||
return new ShardingTransaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
}; | ||
@@ -871,2 +920,3 @@ TransactionFactory.prototype.clone = function (transaction) { | ||
exports.Transaction = Transaction; | ||
exports.ShardingTransaction = ShardingTransaction; | ||
exports.transactionFields = transactionFields; | ||
@@ -873,0 +923,0 @@ exports.transactionFieldsETH = transactionFieldsETH; |
export * from './factory'; | ||
export * from './transaction'; | ||
export * from './shardingTransaction'; | ||
export * from './types'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,3 +5,3 @@ /** | ||
import { hexToNumber, isHex, isAddress, strip0x, add0xToString, numberToHex, Unit } from '@harmony-js/utils'; | ||
import { hexToNumber, isHex, isAddress, strip0x, add0xToString, numberToHex, Unit, AddressSuffix } from '@harmony-js/utils'; | ||
import { decode, encode, keccak256, hexlify, BN, hexZeroPad, recoverAddress, getAddress, sign, arrayify, stripZeros, splitSignature, HarmonyAddress, getContractAddress } from '@harmony-js/crypto'; | ||
@@ -24,3 +24,17 @@ import { HttpProvider, Messenger, Emitter, NewHeaders } from '@harmony-js/network'; | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
@@ -201,4 +215,3 @@ __assign = Object.assign || function __assign(t) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -280,4 +293,3 @@ catch (error) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -305,3 +317,3 @@ catch (error) { | ||
})(TransactionEvents || (TransactionEvents = {})); | ||
var defaultMessenger = new Messenger(new HttpProvider('http://localhost:8545'), "hmy" /* Harmony */); | ||
var defaultMessenger = new Messenger(new HttpProvider('http://localhost:9500'), "hmy" /* Harmony */); | ||
var RLPSign = function (transaction, prv) { | ||
@@ -533,3 +545,2 @@ var _a = __read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1]; | ||
case 0: | ||
// TODO: we use eth RPC setting for now, incase we have other params, we should add here | ||
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) { | ||
@@ -541,3 +552,3 @@ throw new Error('Transaction not signed'); | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction, this.messenger.chainType, typeof this.shardID === 'string' ? Number.parseInt(this.shardID, 10) : this.shardID)]; | ||
case 1: | ||
@@ -567,3 +578,4 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.trackTx = function (txHash) { | ||
Transaction.prototype.trackTx = function (txHash, shardID) { | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -577,3 +589,3 @@ var res, currentBlock, currentBlock; | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash, this.messenger.chainType, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)]; | ||
case 1: | ||
@@ -622,5 +634,6 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval) { | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval, shardID) { | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (interval === void 0) { interval = 1000; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -650,3 +663,3 @@ var oldBlock, checkBlock, attempt, newBlock, nextBlock, err_1, result, error_1; | ||
checkBlock = newBlock; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 5: | ||
@@ -684,3 +697,3 @@ if (_a.sent()) { | ||
_a.trys.push([13, 18, , 19]); | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 14: | ||
@@ -690,3 +703,3 @@ if (!_a.sent()) return [3 /*break*/, 15]; | ||
return [2 /*return*/, this]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts)]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts, shardID)]; | ||
case 16: | ||
@@ -706,7 +719,8 @@ result = _a.sent(); | ||
}; | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts) { | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts, shardID) { | ||
var _this = this; | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return new Promise(function (resolve, reject) { | ||
var newHeads = Promise.resolve(new NewHeaders(_this.messenger)); | ||
var newHeads = Promise.resolve(new NewHeaders(_this.messenger, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)); | ||
newHeads.then(function (p) { | ||
@@ -718,3 +732,3 @@ p.onData(function (data) { return __awaiter(_this, void 0, void 0, function () { | ||
if (!!this.blockNumbers.includes(data.params.result.number)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 1: | ||
@@ -830,2 +844,34 @@ if (!_a.sent()) return [3 /*break*/, 3]; | ||
var ShardingTransaction = /** @class */ (function (_super) { | ||
__extends(ShardingTransaction, _super); | ||
function ShardingTransaction(params, messenger, txStatus) { | ||
if (messenger === void 0) { messenger = defaultMessenger; } | ||
if (txStatus === void 0) { txStatus = "INITIALIZED" /* INTIALIZED */; } | ||
var _this = this; | ||
var fromAddress = params.from; | ||
var toAddress = params.to; | ||
var fromExtraction = fromAddress !== undefined ? fromAddress.split(AddressSuffix) : ['0x', undefined]; | ||
var toExtraction = toAddress !== undefined ? toAddress.split(AddressSuffix) : ['0x', undefined]; | ||
var from = fromExtraction[0]; | ||
var shardID = fromExtraction[1] !== undefined | ||
? Number.parseInt(fromExtraction[1], 10) | ||
: params.shardID !== undefined | ||
? params.shardID | ||
: 0; | ||
var to = toExtraction[0]; | ||
var toShardID = toExtraction[1] !== undefined | ||
? Number.parseInt(toExtraction[1], 10) | ||
: params.toShardID !== undefined | ||
? params.toShardID | ||
: 0; | ||
var reParams = __assign({}, params, { from: from, | ||
to: to, | ||
shardID: shardID, | ||
toShardID: toShardID }); | ||
_this = _super.call(this, reParams, messenger, txStatus) || this; | ||
return _this; | ||
} | ||
return ShardingTransaction; | ||
}(Transaction)); | ||
var TransactionFactory = /** @class */ (function () { | ||
@@ -837,4 +883,3 @@ function TransactionFactory(messenger) { | ||
var _a = tx.txParams, from = _a.from, nonce = _a.nonce; | ||
return getAddress(getContractAddress(from, Number.parseInt("" + nonce, 10))) | ||
.checksum; | ||
return getAddress(getContractAddress(from, Number.parseInt("" + nonce, 10))).checksum; | ||
}; | ||
@@ -844,4 +889,8 @@ TransactionFactory.prototype.setMessenger = function (messenger) { | ||
}; | ||
TransactionFactory.prototype.newTx = function (txParams) { | ||
return new Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
TransactionFactory.prototype.newTx = function (txParams, sharding) { | ||
if (sharding === void 0) { sharding = false; } | ||
if (!sharding) { | ||
return new Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
} | ||
return new ShardingTransaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
}; | ||
@@ -868,3 +917,3 @@ TransactionFactory.prototype.clone = function (transaction) { | ||
export { TransactionFactory, Transaction, TxStatus, transactionFields, transactionFieldsETH, handleNumber, handleAddress, recover, recoverETH, sleep, TransactionEvents, defaultMessenger, RLPSign }; | ||
export { TransactionFactory, Transaction, ShardingTransaction, TxStatus, transactionFields, transactionFieldsETH, handleNumber, handleAddress, recover, recoverETH, sleep, TransactionEvents, defaultMessenger, RLPSign }; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -6,4 +6,5 @@ "use strict"; | ||
tslib_1.__exportStar(require("./transaction"), exports); | ||
tslib_1.__exportStar(require("./shardingTransaction"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
tslib_1.__exportStar(require("./utils"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -25,3 +25,17 @@ /** | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
@@ -202,4 +216,3 @@ __assign = Object.assign || function __assign(t) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -281,4 +294,3 @@ catch (error) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : crypto.getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -305,3 +317,3 @@ catch (error) { | ||
})(exports.TransactionEvents || (exports.TransactionEvents = {})); | ||
var defaultMessenger = new network.Messenger(new network.HttpProvider('http://localhost:8545'), "hmy" /* Harmony */); | ||
var defaultMessenger = new network.Messenger(new network.HttpProvider('http://localhost:9500'), "hmy" /* Harmony */); | ||
var RLPSign = function (transaction, prv) { | ||
@@ -533,3 +545,2 @@ var _a = __read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1]; | ||
case 0: | ||
// TODO: we use eth RPC setting for now, incase we have other params, we should add here | ||
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) { | ||
@@ -541,3 +552,3 @@ throw new Error('Transaction not signed'); | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction, this.messenger.chainType, typeof this.shardID === 'string' ? Number.parseInt(this.shardID, 10) : this.shardID)]; | ||
case 1: | ||
@@ -567,3 +578,4 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.trackTx = function (txHash) { | ||
Transaction.prototype.trackTx = function (txHash, shardID) { | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -577,3 +589,3 @@ var res, currentBlock, currentBlock; | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash, this.messenger.chainType, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)]; | ||
case 1: | ||
@@ -622,5 +634,6 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval) { | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval, shardID) { | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (interval === void 0) { interval = 1000; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -650,3 +663,3 @@ var oldBlock, checkBlock, attempt, newBlock, nextBlock, err_1, result, error_1; | ||
checkBlock = newBlock; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 5: | ||
@@ -684,3 +697,3 @@ if (_a.sent()) { | ||
_a.trys.push([13, 18, , 19]); | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 14: | ||
@@ -690,3 +703,3 @@ if (!_a.sent()) return [3 /*break*/, 15]; | ||
return [2 /*return*/, this]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts)]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts, shardID)]; | ||
case 16: | ||
@@ -706,7 +719,8 @@ result = _a.sent(); | ||
}; | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts) { | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts, shardID) { | ||
var _this = this; | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return new Promise(function (resolve, reject) { | ||
var newHeads = Promise.resolve(new network.NewHeaders(_this.messenger)); | ||
var newHeads = Promise.resolve(new network.NewHeaders(_this.messenger, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)); | ||
newHeads.then(function (p) { | ||
@@ -718,3 +732,3 @@ p.onData(function (data) { return __awaiter(_this, void 0, void 0, function () { | ||
if (!!this.blockNumbers.includes(data.params.result.number)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 1: | ||
@@ -830,2 +844,34 @@ if (!_a.sent()) return [3 /*break*/, 3]; | ||
var ShardingTransaction = /** @class */ (function (_super) { | ||
__extends(ShardingTransaction, _super); | ||
function ShardingTransaction(params, messenger, txStatus) { | ||
if (messenger === void 0) { messenger = defaultMessenger; } | ||
if (txStatus === void 0) { txStatus = "INITIALIZED" /* INTIALIZED */; } | ||
var _this = this; | ||
var fromAddress = params.from; | ||
var toAddress = params.to; | ||
var fromExtraction = fromAddress !== undefined ? fromAddress.split(utils.AddressSuffix) : ['0x', undefined]; | ||
var toExtraction = toAddress !== undefined ? toAddress.split(utils.AddressSuffix) : ['0x', undefined]; | ||
var from = fromExtraction[0]; | ||
var shardID = fromExtraction[1] !== undefined | ||
? Number.parseInt(fromExtraction[1], 10) | ||
: params.shardID !== undefined | ||
? params.shardID | ||
: 0; | ||
var to = toExtraction[0]; | ||
var toShardID = toExtraction[1] !== undefined | ||
? Number.parseInt(toExtraction[1], 10) | ||
: params.toShardID !== undefined | ||
? params.toShardID | ||
: 0; | ||
var reParams = __assign({}, params, { from: from, | ||
to: to, | ||
shardID: shardID, | ||
toShardID: toShardID }); | ||
_this = _super.call(this, reParams, messenger, txStatus) || this; | ||
return _this; | ||
} | ||
return ShardingTransaction; | ||
}(Transaction)); | ||
var TransactionFactory = /** @class */ (function () { | ||
@@ -837,4 +883,3 @@ function TransactionFactory(messenger) { | ||
var _a = tx.txParams, from = _a.from, nonce = _a.nonce; | ||
return crypto.getAddress(crypto.getContractAddress(from, Number.parseInt("" + nonce, 10))) | ||
.checksum; | ||
return crypto.getAddress(crypto.getContractAddress(from, Number.parseInt("" + nonce, 10))).checksum; | ||
}; | ||
@@ -844,4 +889,8 @@ TransactionFactory.prototype.setMessenger = function (messenger) { | ||
}; | ||
TransactionFactory.prototype.newTx = function (txParams) { | ||
return new Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
TransactionFactory.prototype.newTx = function (txParams, sharding) { | ||
if (sharding === void 0) { sharding = false; } | ||
if (!sharding) { | ||
return new Transaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
} | ||
return new ShardingTransaction(txParams, this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
}; | ||
@@ -869,2 +918,3 @@ TransactionFactory.prototype.clone = function (transaction) { | ||
exports.Transaction = Transaction; | ||
exports.ShardingTransaction = ShardingTransaction; | ||
exports.transactionFields = transactionFields; | ||
@@ -871,0 +921,0 @@ exports.transactionFieldsETH = transactionFieldsETH; |
@@ -56,5 +56,5 @@ /// <reference types="bn.js" /> | ||
sendTransaction(): Promise<[Transaction, string]>; | ||
trackTx(txHash: string): Promise<boolean>; | ||
confirm(txHash: string, maxAttempts?: number, interval?: number): Promise<Transaction>; | ||
socketConfirm(txHash: string, maxAttempts?: number): Promise<Transaction>; | ||
trackTx(txHash: string, shardID?: number | string): Promise<boolean>; | ||
confirm(txHash: string, maxAttempts?: number, interval?: number, shardID?: number | string): Promise<Transaction>; | ||
socketConfirm(txHash: string, maxAttempts?: number, shardID?: number | string): Promise<Transaction>; | ||
emitTransactionHash(transactionHash: string): void; | ||
@@ -61,0 +61,0 @@ emitReceipt(receipt: any): void; |
@@ -225,3 +225,2 @@ "use strict"; | ||
case 0: | ||
// TODO: we use eth RPC setting for now, incase we have other params, we should add here | ||
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) { | ||
@@ -233,3 +232,3 @@ throw new Error('Transaction not signed'); | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_sendRawTransaction" /* SendRawTransaction */, this.rawTransaction, this.messenger.chainType, typeof this.shardID === 'string' ? Number.parseInt(this.shardID, 10) : this.shardID)]; | ||
case 1: | ||
@@ -259,3 +258,4 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.trackTx = function (txHash) { | ||
Transaction.prototype.trackTx = function (txHash, shardID) { | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
@@ -269,3 +269,3 @@ var res, currentBlock, currentBlock; | ||
} | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash)]; | ||
return [4 /*yield*/, this.messenger.send("hmy_getTransactionReceipt" /* GetTransactionReceipt */, txHash, this.messenger.chainType, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)]; | ||
case 1: | ||
@@ -314,5 +314,6 @@ res = _a.sent(); | ||
}; | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval) { | ||
Transaction.prototype.confirm = function (txHash, maxAttempts, interval, shardID) { | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (interval === void 0) { interval = 1000; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
@@ -342,3 +343,3 @@ var oldBlock, checkBlock, attempt, newBlock, nextBlock, err_1, result, error_1; | ||
checkBlock = newBlock; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 5: | ||
@@ -376,3 +377,3 @@ if (_a.sent()) { | ||
_a.trys.push([13, 18, , 19]); | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 14: | ||
@@ -382,3 +383,3 @@ if (!_a.sent()) return [3 /*break*/, 15]; | ||
return [2 /*return*/, this]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts)]; | ||
case 15: return [4 /*yield*/, this.socketConfirm(txHash, maxAttempts, shardID)]; | ||
case 16: | ||
@@ -398,7 +399,8 @@ result = _a.sent(); | ||
}; | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts) { | ||
Transaction.prototype.socketConfirm = function (txHash, maxAttempts, shardID) { | ||
var _this = this; | ||
if (maxAttempts === void 0) { maxAttempts = 20; } | ||
if (shardID === void 0) { shardID = this.shardID; } | ||
return new Promise(function (resolve, reject) { | ||
var newHeads = Promise.resolve(new network_1.NewHeaders(_this.messenger)); | ||
var newHeads = Promise.resolve(new network_1.NewHeaders(_this.messenger, typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID)); | ||
newHeads.then(function (p) { | ||
@@ -410,3 +412,3 @@ p.onData(function (data) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
if (!!this.blockNumbers.includes(data.params.result.number)) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.trackTx(txHash)]; | ||
return [4 /*yield*/, this.trackTx(txHash, shardID)]; | ||
case 1: | ||
@@ -413,0 +415,0 @@ if (!_a.sent()) return [3 /*break*/, 3]; |
@@ -117,4 +117,3 @@ "use strict"; | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : crypto_1.getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : crypto_1.getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -196,4 +195,3 @@ catch (error) { | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : crypto_1.getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : crypto_1.getAddress(recoveredFrom).checksum; | ||
} | ||
@@ -221,3 +219,3 @@ catch (error) { | ||
})(TransactionEvents = exports.TransactionEvents || (exports.TransactionEvents = {})); | ||
exports.defaultMessenger = new network_1.Messenger(new network_1.HttpProvider('http://localhost:8545'), "hmy" /* Harmony */); | ||
exports.defaultMessenger = new network_1.Messenger(new network_1.HttpProvider('http://localhost:9500'), "hmy" /* Harmony */); | ||
exports.RLPSign = function (transaction, prv) { | ||
@@ -224,0 +222,0 @@ var _a = tslib_1.__read(transaction.getRLPUnsigned(), 2), unsignedRawTransaction = _a[0], raw = _a[1]; |
{ | ||
"name": "@harmony-js/transaction", | ||
"version": "0.1.7", | ||
"version": "0.1.12", | ||
"description": "transaction package for harmony", | ||
@@ -21,7 +21,7 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@harmony-js/crypto": "0.1.7", | ||
"@harmony-js/network": "0.1.7", | ||
"@harmony-js/utils": "0.1.6" | ||
"@harmony-js/crypto": "0.1.12", | ||
"@harmony-js/network": "0.1.12", | ||
"@harmony-js/utils": "0.1.12" | ||
}, | ||
"gitHead": "b2300964739641778b379b575fdaf45bff34740b" | ||
"gitHead": "b6b3ff2a6830cfae9db3301b88e1fe636657c7ae" | ||
} |
import { getContractAddress, getAddress } from '@harmony-js/crypto'; | ||
import { Messenger } from '@harmony-js/network'; | ||
import { Transaction } from './transaction'; | ||
import { ShardingTransaction } from './shardingTransaction'; | ||
import { TxParams, TxStatus } from './types'; | ||
@@ -9,4 +10,3 @@ | ||
const { from, nonce } = tx.txParams; | ||
return getAddress(getContractAddress(from, Number.parseInt(`${nonce}`, 10))) | ||
.checksum; | ||
return getAddress(getContractAddress(from, Number.parseInt(`${nonce}`, 10))).checksum; | ||
} | ||
@@ -22,12 +22,11 @@ | ||
newTx(txParams?: TxParams | any): Transaction { | ||
return new Transaction(txParams, this.messenger, TxStatus.INTIALIZED); | ||
newTx(txParams?: TxParams | any, sharding: boolean = false): Transaction { | ||
if (!sharding) { | ||
return new Transaction(txParams, this.messenger, TxStatus.INTIALIZED); | ||
} | ||
return new ShardingTransaction(txParams, this.messenger, TxStatus.INTIALIZED); | ||
} | ||
clone(transaction: Transaction): Transaction { | ||
return new Transaction( | ||
transaction.txParams, | ||
this.messenger, | ||
TxStatus.INTIALIZED, | ||
); | ||
return new Transaction(transaction.txParams, this.messenger, TxStatus.INTIALIZED); | ||
} | ||
@@ -34,0 +33,0 @@ |
export * from './factory'; | ||
export * from './transaction'; | ||
export * from './shardingTransaction'; | ||
export * from './types'; | ||
export * from './utils'; |
@@ -41,2 +41,3 @@ import { | ||
receipt?: TransasctionReceipt; | ||
private id: string; | ||
@@ -100,2 +101,3 @@ private from: string; | ||
}; | ||
this.receipt = params && params.receipt ? params.receipt : undefined; | ||
@@ -286,3 +288,2 @@ } | ||
async sendTransaction(): Promise<[Transaction, string]> { | ||
// TODO: we use eth RPC setting for now, incase we have other params, we should add here | ||
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) { | ||
@@ -294,4 +295,13 @@ throw new Error('Transaction not signed'); | ||
} | ||
const res = await this.messenger.send(RPCMethod.SendRawTransaction, this.rawTransaction); | ||
// const fromShard = this.shardID; | ||
// const toShard = this.toShardID; | ||
// await this.messenger.setShardingProviders(); | ||
const res = await this.messenger.send( | ||
RPCMethod.SendRawTransaction, | ||
this.rawTransaction, | ||
this.messenger.chainType, | ||
typeof this.shardID === 'string' ? Number.parseInt(this.shardID, 10) : this.shardID, | ||
); | ||
// temporarilly hard coded | ||
@@ -314,3 +324,3 @@ if (res.isResult()) { | ||
async trackTx(txHash: string) { | ||
async trackTx(txHash: string, shardID: number | string = this.shardID) { | ||
if (!this.messenger) { | ||
@@ -320,3 +330,8 @@ throw new Error('Messenger not found'); | ||
// TODO: regex validation for txHash so we don't get garbage | ||
const res = await this.messenger.send(RPCMethod.GetTransactionReceipt, txHash); | ||
const res = await this.messenger.send( | ||
RPCMethod.GetTransactionReceipt, | ||
txHash, | ||
this.messenger.chainType, | ||
typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID, | ||
); | ||
@@ -359,3 +374,8 @@ if (res.isResult() && res.result !== null) { | ||
async confirm(txHash: string, maxAttempts: number = 20, interval: number = 1000) { | ||
async confirm( | ||
txHash: string, | ||
maxAttempts: number = 20, | ||
interval: number = 1000, | ||
shardID: number | string = this.shardID, | ||
) { | ||
if (this.messenger.provider instanceof HttpProvider) { | ||
@@ -375,3 +395,3 @@ this.txStatus = TxStatus.PENDING; | ||
if (await this.trackTx(txHash)) { | ||
if (await this.trackTx(txHash, shardID)) { | ||
this.emitConfirm(this.txStatus); | ||
@@ -399,7 +419,7 @@ return this; | ||
try { | ||
if (await this.trackTx(txHash)) { | ||
if (await this.trackTx(txHash, shardID)) { | ||
this.emitConfirm(this.txStatus); | ||
return this; | ||
} else { | ||
const result = await this.socketConfirm(txHash, maxAttempts); | ||
const result = await this.socketConfirm(txHash, maxAttempts, shardID); | ||
return result; | ||
@@ -417,9 +437,18 @@ } | ||
socketConfirm(txHash: string, maxAttempts: number = 20): Promise<Transaction> { | ||
socketConfirm( | ||
txHash: string, | ||
maxAttempts: number = 20, | ||
shardID: number | string = this.shardID, | ||
): Promise<Transaction> { | ||
return new Promise((resolve, reject) => { | ||
const newHeads = Promise.resolve(new NewHeaders(this.messenger)); | ||
const newHeads = Promise.resolve( | ||
new NewHeaders( | ||
this.messenger, | ||
typeof shardID === 'string' ? Number.parseInt(shardID, 10) : shardID, | ||
), | ||
); | ||
newHeads.then((p) => { | ||
p.onData(async (data: any) => { | ||
if (!this.blockNumbers.includes(data.params.result.number)) { | ||
if (await this.trackTx(txHash)) { | ||
if (await this.trackTx(txHash, shardID)) { | ||
this.emitConfirm(this.txStatus); | ||
@@ -426,0 +455,0 @@ await p.unsubscribe(); |
@@ -1,2 +0,2 @@ | ||
import {BN, Signature} from '@harmony-js/crypto'; | ||
import { BN, Signature } from '@harmony-js/crypto'; | ||
export interface TxParams { | ||
@@ -3,0 +3,0 @@ id: string; |
@@ -0,9 +1,3 @@ | ||
import { hexToNumber, isHex, isAddress, strip0x, ChainType } from '@harmony-js/utils'; | ||
import { | ||
hexToNumber, | ||
isHex, | ||
isAddress, | ||
strip0x, | ||
ChainType, | ||
} from '@harmony-js/utils'; | ||
import { | ||
decode, | ||
@@ -144,4 +138,3 @@ encode, | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
} catch (error) { | ||
@@ -173,2 +166,3 @@ throw error; | ||
toShardID: 0, | ||
to: | ||
@@ -237,4 +231,3 @@ handleAddress(transaction[3]) !== '0x' | ||
}); | ||
tx.from = | ||
recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
tx.from = recoveredFrom === '0x' ? '0x' : getAddress(recoveredFrom).checksum; | ||
} catch (error) { | ||
@@ -263,10 +256,7 @@ throw error; | ||
export const defaultMessenger = new Messenger( | ||
new HttpProvider('http://localhost:8545'), | ||
new HttpProvider('http://localhost:9500'), | ||
ChainType.Harmony, | ||
); | ||
export const RLPSign = ( | ||
transaction: Transaction, | ||
prv: string, | ||
): [Signature, string] => { | ||
export const RLPSign = (transaction: Transaction, prv: string): [Signature, string] => { | ||
const [unsignedRawTransaction, raw] = transaction.getRLPUnsigned(); | ||
@@ -273,0 +263,0 @@ const regroup: TxParams = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
510481
44
5477
+ Added@harmony-js/crypto@0.1.12(transitive)
+ Added@harmony-js/network@0.1.12(transitive)
+ Added@harmony-js/utils@0.1.12(transitive)
- Removed@harmony-js/crypto@0.1.7(transitive)
- Removed@harmony-js/network@0.1.7(transitive)
- Removed@harmony-js/utils@0.1.6(transitive)
Updated@harmony-js/crypto@0.1.12
Updated@harmony-js/network@0.1.12
Updated@harmony-js/utils@0.1.12