@parity/api
Version:
The Parity Promise-based API library for interfacing with Ethereum over RPC
338 lines (337 loc) • 15.4 kB
JavaScript
"use strict";
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
var __extends = (this && this.__extends) || (function () {
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);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
var PubsubBase = require('../pubsubBase');
var _a = require('../../format/input'), inAddress = _a.inAddress, inBlockNumber = _a.inBlockNumber, inData = _a.inData, inHex = _a.inHex, inDeriveHash = _a.inDeriveHash, inDeriveIndex = _a.inDeriveIndex;
var _b = require('../../format/output'), outAccountInfo = _b.outAccountInfo, outAddress = _b.outAddress, outBlock = _b.outBlock, outBlockReceipts = _b.outBlockReceipts, outChainStatus = _b.outChainStatus, outHistogram = _b.outHistogram, outHwAccountInfo = _b.outHwAccountInfo, outNodeKind = _b.outNodeKind, outNumber = _b.outNumber, outPeers = _b.outPeers, outTransaction = _b.outTransaction, outAddresses = _b.outAddresses, outRecentDapps = _b.outRecentDapps, outVaultMeta = _b.outVaultMeta;
var Parity = /** @class */ (function (_super) {
__extends(Parity, _super);
function Parity(provider) {
var _this = _super.call(this, provider) || this;
_this._api = 'parity';
return _this;
}
// parity API
Parity.prototype.accountsInfo = function (callback) {
return this.addListener(this._api, 'parity_accountsInfo', function (error, data) {
error
? callback(error)
: callback(null, outAccountInfo(data));
});
};
Parity.prototype.allAccountsInfo = function (callback) {
return this.addListener(this._api, 'parity_allAccountsInfo', function (error, data) {
error
? callback(error)
: callback(null, outAccountInfo(data));
});
};
Parity.prototype.hardwareAccountsInfo = function (callback) {
return this.addListener(this._api, 'parity_hardwareAccountsInfo', function (error, data) {
error
? callback(error)
: callback(null, outHwAccountInfo(data));
});
};
Parity.prototype.defaultAccount = function (callback) {
return this.addListener(this._api, 'parity_defaultAccount', function (error, data) {
error
? callback(error)
: callback(null, outAddress(data));
});
};
Parity.prototype.transactionsLimit = function (callback) {
return this.addListener(this._api, 'parity_transactionsLimit', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
});
};
Parity.prototype.extraData = function (callback) {
return this.addListener(this._api, 'parity_extraData', callback);
};
Parity.prototype.gasFloorTarget = function (callback) {
return this.addListener(this._api, 'parity_gasFloorTarget', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
});
};
Parity.prototype.gasCeilTarget = function (callback) {
return this.addListener(this._api, 'parity_gasCeilTarget', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
});
};
Parity.prototype.minGasPrice = function (callback) {
return this.addListener(this._api, 'parity_minGasPrice', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
});
};
Parity.prototype.devLogs = function (callback) {
return this.addListener(this._api, 'parity_devLogs', callback);
};
Parity.prototype.devLogsLevels = function (callback) {
return this.addListener(this._api, 'parity_devLogsLevels', callback);
};
Parity.prototype.netChain = function (callback) {
return this.addListener(this._api, 'parity_netChain', callback);
};
Parity.prototype.netPeers = function (callback) {
return this.addListener(this._api, 'parity_netPeers', function (error, data) {
error
? callback(error)
: callback(null, outPeers(data));
});
};
Parity.prototype.netPort = function (callback) {
return this.addListener(this._api, 'parity_netPort', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
});
};
Parity.prototype.rpcSettings = function (callback) {
return this.addListener(this._api, 'parity_rpcSettings', callback);
};
Parity.prototype.nodeName = function (callback) {
return this.addListener(this._api, 'parity_nodeName', callback);
};
Parity.prototype.defaultExtraData = function (callback) {
return this.addListener(this._api, 'parity_defaultExtraData', callback);
};
Parity.prototype.gasPriceHistogram = function (callback) {
return this.addListener(this._api, 'parity_gasPriceHistogram', function (error, data) {
error
? callback(error)
: callback(null, outHistogram(data));
});
};
Parity.prototype.unsignedTransactionsCount = function (callback) {
return this.addListener(this._api, 'parity_unsignedTransactionsCount', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
});
};
Parity.prototype.registryAddress = function (callback) {
return this.addListener(this._api, 'parity_registryAddress', function (error, data) {
error
? callback(error)
: callback(null, outAddress(data));
});
};
Parity.prototype.listAccounts = function (callback, count, offset, blockNumber) {
if (offset === void 0) { offset = null; }
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this.addListener(this._api, 'parity_listAccounts', function (error, data) {
error
? callback(error)
: callback(null, function (data) { return (data || []).map(outAddress); });
}, [count, inAddress(offset), inBlockNumber(blockNumber)]);
};
Parity.prototype.listStorageKeys = function (callback, address, count, hash, blockNumber) {
if (hash === void 0) { hash = null; }
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this.addListener(this._api, 'parity_listStorageKeys', callback, [inAddress(address), count, inHex(hash), inBlockNumber(blockNumber)]);
};
Parity.prototype.pendingTransactions = function (callback) {
return this.addListener(this._api, 'parity_pendingTransactions', function (error, data) {
error
? callback(error)
: callback(null, outTransaction(data));
});
};
Parity.prototype.futureTransactions = function (callback) {
return this.addListener(this._api, 'parity_futureTransactions', function (error, data) {
error
? callback(error)
: callback(null, outTransaction(data));
});
};
Parity.prototype.pendingTransactionsStats = function (callback) {
return this.addListener(this._api, 'parity_pendingTransactionsStats', callback);
};
Parity.prototype.localTransactions = function (callback) {
return this.addListener(this._api, 'parity_localTransactions', function (error, transactions) {
if (error) {
return callback(error);
}
Object
.values(transactions)
.filter(function (tx) { return tx.transaction; })
.forEach(function (tx) {
tx.transaction = outTransaction(tx.transaction);
});
callback(null, transactions);
});
};
Parity.prototype.dappsUrl = function (callback) {
return this.addListener(this._api, 'parity_dappsUrl', callback);
};
Parity.prototype.wsUrl = function (callback) {
return this.addListener(this._api, 'parity_wsUrl', callback);
};
Parity.prototype.nextNonce = function (callback, account) {
return this.addListener(this._api, 'parity_nextNonce', function (error, data) {
error
? callback(error)
: callback(null, outNumber(data));
}, [inAddress(account)]);
};
Parity.prototype.mode = function (callback) {
return this.addListener(this._api, 'parity_mode', callback);
};
Parity.prototype.chain = function (callback) {
return this.addListener(this._api, 'parity_chain', callback);
};
Parity.prototype.enode = function (callback) {
return this.addListener(this._api, 'parity_enode', callback);
};
Parity.prototype.consensusCapability = function (callback) {
return this.addListener(this._api, 'parity_consensusCapability', callback);
};
Parity.prototype.versionInfo = function (callback) {
return this.addListener(this._api, 'parity_versionInfo', callback);
};
Parity.prototype.releasesInfo = function (callback) {
return this.addListener(this._api, 'parity_releasesInfo', callback);
};
Parity.prototype.chainStatus = function (callback) {
return this.addListener(this._api, 'parity_chainStatus', function (error, data) {
error
? callback(error)
: callback(null, outChainStatus(data));
});
};
Parity.prototype.nodeKind = function (callback) {
return this.addListener(this._api, 'parity_nodeKind', function (error, data) {
error
? callback(error)
: callback(null, outNodeKind(data));
});
};
Parity.prototype.getBlockHeaderByNumber = function (callback, blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this.addListener(this._api, 'parity_getBlockHeaderByNumber', function (error, data) {
error
? callback(error)
: callback(null, outBlock(data));
}, [inBlockNumber(blockNumber)]);
};
Parity.prototype.getBlockReceipts = function (callback, blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this.addListener(this._api, 'parity_getBlockReceipts', function (error, data) {
error
? callback(error)
: callback(null, outBlockReceipts(data));
}, [inBlockNumber(blockNumber)]);
};
Parity.prototype.cidV0 = function (callback, data) {
return this.addListener(this._api, 'parity_cidV0', callback, [inData(data)]);
};
Parity.prototype.getDappAddresses = function (callback, dappId) {
return this.addListener(this._api, 'parity_getDappAddresses', function (error, data) {
error
? callback(error)
: callback(null, outAddresses(data));
}, [dappId]);
};
Parity.prototype.getDappDefaultAddress = function (callback, dappId) {
return this.addListener(this._api, 'parity_getDappDefaultAddress', function (error, data) {
error
? callback(error)
: callback(null, outAddress(data));
}, [dappId]);
};
Parity.prototype.getNewDappsAddresses = function (callback) {
return this.addListener(this._api, 'parity_getDappDefaultAddress', function (error, addresses) {
error
? callback(error)
: callback(null, addresses ? addresses.map(outAddress) : null);
});
};
Parity.prototype.getNewDappsDefaultAddress = function (callback) {
return this.addListener(this._api, 'parity_getNewDappsDefaultAddress', function (error, data) {
error
? callback(error)
: callback(null, outAddress(data));
});
};
Parity.prototype.listRecentDapps = function (callback) {
return this.addListener(this._api, 'parity_listRecentDapps', function (error, data) {
error
? callback(error)
: callback(null, outRecentDapps(data));
});
};
Parity.prototype.listGethAccounts = function (callback) {
return this.addListener(this._api, 'parity_listGethAccounts', function (error, data) {
error
? callback(error)
: callback(null, outAddresses(data));
});
};
Parity.prototype.listVaults = function (callback) {
return this.addListener(this._api, 'parity_listVaults', callback);
};
Parity.prototype.listOpenedVaults = function (callback) {
return this.addListener(this._api, 'parity_listOpenedVaults', callback);
};
Parity.prototype.getVaultMeta = function (callback, vaultName) {
return this.addListener(this._api, 'parity_getVaultMeta', function (error, data) {
error
? callback(error)
: callback(null, outVaultMeta(data));
}, [vaultName]);
};
Parity.prototype.deriveAddressHash = function (callback, address, password, hash, shouldSave) {
return this.addListener(this._api, 'parity_deriveAddressHash', function (error, data) {
error
? callback(error)
: callback(null, outAddress(data));
}, [inAddress(address), password, inDeriveHash(hash), !!shouldSave]);
};
Parity.prototype.deriveAddressIndex = function (callback, address, password, index, shouldSave) {
return this.addListener(this._api, 'parity_deriveAddressIndex', function (error, data) {
error
? callback(error)
: callback(null, outAddress(data));
}, [inAddress(address), password, inDeriveIndex(index), !!shouldSave]);
};
Parity.prototype.nodeHealth = function (callback) {
return this.addListener(this._api, 'parity_nodeHealth', function (error, data) {
error
? callback(error)
: callback(null, data);
});
};
return Parity;
}(PubsubBase));
module.exports = Parity;