Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
function claimToken() {
var email = Math.random() + "[email protected]";
var url = "https://testnet.nebulas.io/claim/api/claim/"+ email+ "/"+ account.getAddressString() +"/";
var request = new Neb.HttpRequest(url);
var request = new HttpRequest(url);
request.request("GET", "", "").then(function (resp) {
console.log(resp);
}).catch(function (err) {
Expand Down
34 changes: 4 additions & 30 deletions lib/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict";

var utils = require('./utils/utils.js');
var Transaction = require("./transaction.js");

/**
* Admin API constructor.
Expand Down Expand Up @@ -158,16 +159,7 @@ Admin.prototype.lockAccount = function (options) {
*/
Admin.prototype.sendTransaction = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary'], arguments);
var params = {
"from": options.from,
"to": options.to,
"value": utils.toString(options.value),
"nonce": options.nonce,
"gasPrice": utils.toString(options.gasPrice),
"gasLimit": utils.toString(options.gasLimit),
"contract": options.contract,
"binary": options.binary
};
var params = new Transaction(options).toPlainObject();
return this._sendRequest("post", "/transaction", params);
};

Expand Down Expand Up @@ -228,16 +220,7 @@ Admin.prototype.signHash = function (options) {
*/
Admin.prototype.signTransactionWithPassphrase = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary', 'passphrase'], arguments);
var tx = {
"from": options.from,
"to": options.to,
"value": utils.toString(options.value),
"nonce": options.nonce,
"gasPrice": utils.toString(options.gasPrice),
"gasLimit": utils.toString(options.gasLimit),
"contract": options.contract,
"binary": options.binary
};
var tx = new Transaction(options).toPlainObject();
var params = {
"transaction": tx,
"passphrase": options.passphrase
Expand Down Expand Up @@ -270,16 +253,7 @@ Admin.prototype.signTransactionWithPassphrase = function (options) {
*/
Admin.prototype.sendTransactionWithPassphrase = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary', 'passphrase'], arguments);
var tx = {
"from": options.from,
"to": options.to,
"value": utils.toString(options.value),
"nonce": options.nonce,
"gasPrice": utils.toString(options.gasPrice),
"gasLimit": utils.toString(options.gasLimit),
"contract": options.contract,
"binary": options.binary
};
var tx = new Transaction(options).toPlainObject();
var params = {
"transaction": tx,
"passphrase": options.passphrase
Expand Down
22 changes: 3 additions & 19 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict";

var utils = require('./utils/utils.js');
var Transaction = require("./transaction.js");

/**
* User API constructor.
Expand Down Expand Up @@ -113,15 +114,7 @@ API.prototype.getAccountState = function (options) {
*/
API.prototype.call = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract'], arguments);
var params = {
"from": options.from,
"to": options.to,
"value": utils.toString(options.value),
"nonce": options.nonce,
"gasPrice": utils.toString(options.gasPrice),
"gasLimit": utils.toString(options.gasLimit),
"contract": options.contract
};
var params = new Transaction(options).toPlainObject();
return this._sendRequest("post", "/call", params);
};

Expand Down Expand Up @@ -302,16 +295,7 @@ API.prototype.gasPrice = function () {
*/
API.prototype.estimateGas = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary'], arguments);
var params = {
"from": options.from,
"to": options.to,
"value": utils.toString(options.value),
"nonce": options.nonce,
"gasPrice": utils.toString(options.gasPrice),
"gasLimit": utils.toString(options.gasLimit),
"contract": options.contract,
"binary": options.binary
};
var params = new Transaction(options).toPlainObject();
return this._sendRequest("post", "/estimateGas", params);
};

Expand Down
10 changes: 8 additions & 2 deletions lib/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ Transaction.prototype = {
* gasLimit: 2000000
* });
* txData = tx.toPlainObject();
* // {chainID: 1001, from: "n1USdDKeZXQYubA44W2ZVUdW1cjiJuqswxp", to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17", value: 1000000000000000000, nonce: 1, …}
* // {chainID: 1001, from: "n1USdDKeZXQYubA44W2ZVUdW1cjiJuqswxp", to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17", value: "1000000000000000000", nonce: 1, …}
*/
toPlainObject: function() {
return {
var resObj = {
chainID: this.chainID,
from: this.from.getAddressString(),
to: this.to.getAddressString(),
Expand All @@ -275,6 +275,12 @@ Transaction.prototype = {
gasLimit: utils.isBigNumber(this.gasLimit) ? this.gasLimit.toNumber() : this.gasLimit,
contract: this.contract
};

resObj.value = utils.toString(resObj.value);
resObj.gasPrice = utils.toString(resObj.gasPrice);
resObj.gasLimit = utils.toString(resObj.gasLimit);

return resObj
},
/**
* Convert transaction to JSON string.
Expand Down