Fixed RPC method calls.
This commit is contained in:
parent
5dc2621a32
commit
06281e85c4
@ -36,21 +36,32 @@ function numberOrBN(value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function zpad(buffer, length) {
|
||||||
|
var zero = new Buffer([0]);
|
||||||
|
while (buffer.length < length) {
|
||||||
|
buffer = Buffer.concat([zero, buffer]);
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
function coderNumber(size, signed) {
|
function coderNumber(size, signed) {
|
||||||
return {
|
return {
|
||||||
encode: function(value) {
|
encode: function(value) {
|
||||||
value = numberOrBN(value)
|
value = numberOrBN(value)
|
||||||
// if (signed) {
|
if (signed) {
|
||||||
return value.toTwos(32 * 8).toArrayLike(Buffer, 'be', 32);
|
value = value.toTwos(32 * 8);
|
||||||
// } else {
|
} else if (value < 0) {
|
||||||
// return value.toArrayLike(Buffer, 'be', 32);
|
value = value.toTwos(size * 8);
|
||||||
// }
|
}
|
||||||
|
return value.toArrayLike(Buffer, 'be', 32);
|
||||||
},
|
},
|
||||||
decode: function(data, offset) {
|
decode: function(data, offset) {
|
||||||
var value = new utils.BN(data.slice(offset, offset + 32));
|
var value = new utils.BN(data.slice(offset, offset + 32));
|
||||||
// if (signed) {
|
if (signed) {
|
||||||
value = value.fromTwos(32 * 8);
|
value = value.fromTwos(size * 8);
|
||||||
// }
|
} else {
|
||||||
|
value = value.mod((new utils.BN(2)).pow(new utils.BN(size * 8)))
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
consumed: 32,
|
consumed: 32,
|
||||||
value: value,
|
value: value,
|
||||||
@ -326,7 +337,7 @@ function Interface(abi) {
|
|||||||
return Interface.decodeParams(
|
return Interface.decodeParams(
|
||||||
outputTypes,
|
outputTypes,
|
||||||
utils.hexOrBuffer(data)
|
utils.hexOrBuffer(data)
|
||||||
)
|
);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
result.type = 'transaction';
|
result.type = 'transaction';
|
||||||
@ -576,8 +587,8 @@ function Contract(provider, wallet, contractAddress, contractInterface) {
|
|||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
provider.client.sendMessage('getTransactionCount', [wallet.address, 'pending']),
|
provider.client.sendMessage('eth_getTransactionCount', [wallet.address, 'pending']),
|
||||||
provider.client.sendMessage('getGasPrice', []),
|
provider.client.sendMessage('eth_gasPrice', []),
|
||||||
]).then(function(results) {
|
]).then(function(results) {
|
||||||
if (transaction.nonce == null) {
|
if (transaction.nonce == null) {
|
||||||
transaction.nonce = results[0];
|
transaction.nonce = results[0];
|
||||||
@ -591,7 +602,7 @@ function Contract(provider, wallet, contractAddress, contractInterface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var signedTransaction = wallet.sign(transaction);
|
var signedTransaction = wallet.sign(transaction);
|
||||||
provider.client.sendMessage('sendRawTransaction', [signedTransaction]).then(function(txid) {
|
provider.client.sendMessage('eth_sendRawTransaction', [signedTransaction]).then(function(txid) {
|
||||||
resolve(txid);
|
resolve(txid);
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user