Added provider standard methods.

This commit is contained in:
ricmoo 2016-08-02 17:41:28 -04:00
parent e4c62d2939
commit 14b15dcf5a

@ -17,14 +17,13 @@ function Web3Connector(provider) {
method: method,
params: params
}, function(error, result) {
//console.log(error, result);
if (error) {
reject(error);
} else {
if (result.code) {
var error = new Error(result.message);
error.code = result.code;
error.data = result.data;
if (result.error) {
var error = new Error(result.error.message);
error.code = result.error.code;
error.data = result.error.data;
reject(error);
} else {
resolve(result.result);
@ -35,7 +34,6 @@ function Web3Connector(provider) {
});
}
function rpcSendAsync(url) {
return {
sendAsync: function(payload, callback) {
@ -82,6 +80,10 @@ function Provider(provider) {
// An ethers.io URL
} else if (provider.substring(0, 5) === 'ws://' || provider.substirng(0, 6) === 'wss://') {
//client =
// Etherscan
} else if (string === 'testnet.etherscan.io' || string === 'etherscan.io') {
// client =
}
// A Web3 Instance
@ -98,5 +100,31 @@ function Provider(provider) {
utils.defineProperty(this, 'client', client);
}
utils.defineProperty(Provider.prototype, 'getBalance', function(address, blockNumber) {
if (blockNumber == null) { blockNumber = 'latest'; }
return this.client.sendMessage('eth_getBalance', [address, blockNumber]);
});
utils.defineProperty(Provider.prototype, 'getTransactionCount', function(address, blockNumber) {
if (blockNumber == null) { blockNumber = 'latest'; }
return this.client.sendMessage('eth_getTransactionCount', [address, blockNumber]);
});
utils.defineProperty(Provider.prototype, 'getGasPrice', function() {
return this.client.sendMessage('eth_gasPrice', []);
});
utils.defineProperty(Provider.prototype, 'sendTransaction', function(signedTransaction) {
return this.client.sendMessage('eth_sendRawTransaction', [signedTransaction]);
});
utils.defineProperty(Provider.prototype, 'call', function(transaction) {
return this.client.sendMessage('eth_call', [transaction]);
});
utils.defineProperty(Provider.prototype, 'estimateGas', function(transaction) {
return this.client.sendMessage('eth_estimateGas', [transaction]);
});
module.exports = Provider;