Skip to content

Commit

Permalink
Auto-generated positional and object parameter methods working: augur…
Browse files Browse the repository at this point in the history
….ContractName.methodName(param1, param2, ...) syntax now supported
  • Loading branch information
tinybike committed Jun 27, 2016
1 parent db6ded2 commit a235ce7
Show file tree
Hide file tree
Showing 42 changed files with 4,861 additions and 3,271 deletions.
6,902 changes: 4,652 additions & 2,250 deletions dist/augur.js

Large diffs are not rendered by default.

51 changes: 26 additions & 25 deletions dist/augur.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GLOBAL.balances = (GLOBAL.balance = function (account, branch) {
account = account || augur.from;
var balances = {
cash: augur.getCashBalance(account),
reputation: augur.getRepBalance(branch || augur.constants.DEFAULT_BRANCH_ID, account),
reputation: augur.Reporting.getRepBalance(branch || augur.constants.DEFAULT_BRANCH_ID, account),
ether: abi.bignum(augur.rpc.balance(account)).dividedBy(constants.ETHER).toFixed()
};
console.log(balances);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"async": "^1.3.0",
"augur-abi": "0.3.6",
"augur-contracts": "1.0.2",
"augur-contracts": "1.0.3",
"bignumber.js": "^2.0.7",
"browser-request": "^0.3.3",
"chalk": "^1.1.1",
Expand Down
6 changes: 0 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ var NODE_JS = (typeof module !== "undefined") && process && !process.browser;
var modules = [
require("./modules/connect"),
require("./modules/transact"),
require("./modules/faucets"),
require("./modules/cash"),
require("./modules/info"),
require("./modules/branches"),
require("./modules/events"),
require("./modules/expiringEvents"),
require("./modules/markets"),
require("./modules/reporting"),
require("./modules/trades"),
require("./modules/buyAndSellShares"),
require("./modules/trade"),
Expand All @@ -26,8 +22,6 @@ var modules = [
require("./modules/sendReputation"),
require("./modules/makeReports"),
require("./modules/createMarket"),
require("./modules/closeMarket"),
require("./modules/consensus"),
require("./modules/compositeGetters"),
require("./modules/whitelist"),
require("./modules/logs"),
Expand Down
69 changes: 0 additions & 69 deletions src/modules/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,6 @@ var utils = require("../utilities");

module.exports = {

initDefaultBranch: function (onSent, onSuccess, onFailed) {
var tx = clone(this.tx.branches.initDefaultBranch);
return this.transact(tx, onSent, onSuccess, onFailed);
},

// getNumBranches: function (callback) {
// return this.fire(this.tx.branches.getNumBranches, callback);
// },

// getBranches: function (callback) {
// return this.fire(this.tx.branches.getBranches, callback);
// },

// getMarketsInBranch: function (branch, callback) {
// // branch: sha256 hash id
// var tx = clone(this.tx.branches.getMarketsInBranch);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getPeriodLength: function (branch, callback) {
// // branch: sha256 hash id
// var tx = clone(this.tx.branches.getPeriodLength);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getVotePeriod: function (branch, callback) {
// // branch: sha256 hash id
// var tx = clone(this.tx.branches.getVotePeriod);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getReportPeriod: function (branch, callback) {
// // branch: sha256 hash id
// var tx = clone(this.tx.branches.getReportPeriod);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getNumMarketsBranch: function (branch, callback) {
// // branch: sha256
// var tx = clone(this.tx.branches.getNumMarketsBranch);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getNumMarkets: function (branch, callback) {
// // branch: sha256
// var tx = clone(this.tx.branches.getNumMarketsBranch);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getMinTradingFee: function (branch, callback) {
// // branch: sha256
// var tx = clone(this.tx.branches.getMinTradingFee);
// tx.params = branch;
// return this.fire(tx, callback);
// },

// getBranchByNum: function (branchNumber, callback) {
// // branchNumber: integer
// var tx = clone(this.tx.branches.getBranchByNum);
// tx.params = branchNumber;
// return this.fire(tx, callback);
// },

getCurrentPeriod: function (branch, callback) {
var self = this;
if (!utils.is_function(callback)) {
Expand Down
11 changes: 2 additions & 9 deletions src/modules/buyAndSellShares.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ var constants = require("../constants");

module.exports = {

cancel: function (trade_id, onSent, onSuccess, onFailed) {
var tx = clone(this.tx.buyAndSellShares.cancel);
var unpacked = utils.unpack(arguments[0], utils.labels(this.cancel), arguments);
tx.params = unpacked.params;
return this.transact.apply(this, [tx].concat(unpacked.cb));
},

buy: function (amount, price, market, outcome, onSent, onSuccess, onFailed) {
var self = this;
if (amount.constructor === Object && amount.amount) {
Expand All @@ -33,7 +26,7 @@ module.exports = {
onSent = onSent || utils.noop;
onSuccess = onSuccess || utils.noop;
onFailed = onFailed || utils.noop;
var tx = clone(this.tx.buyAndSellShares.buy);
var tx = clone(this.tx.BuyAndSellShares.buy);
tx.params = [abi.fix(amount, "hex"), abi.fix(price, "hex"), market, outcome];
this.transact(tx, onSent, function (res) {
res.callReturn = utils.sha3([
Expand Down Expand Up @@ -63,7 +56,7 @@ module.exports = {
onSent = onSent || utils.noop;
onSuccess = onSuccess || utils.noop;
onFailed = onFailed || utils.noop;
var tx = clone(this.tx.buyAndSellShares.sell);
var tx = clone(this.tx.BuyAndSellShares.sell);
tx.params = [abi.fix(amount, "hex"), abi.fix(price, "hex"), market, outcome];
this.transact(tx, onSent, function (res) {
res.callReturn = utils.sha3([
Expand Down
49 changes: 6 additions & 43 deletions src/modules/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,25 @@ var utils = require("../utilities");
module.exports = {

setCash: function (address, balance, onSent, onSuccess, onFailed) {
var tx = clone(this.tx.cash.setCash);
var tx = clone(this.tx.Cash.setCash);
var unpacked = utils.unpack(address, utils.labels(this.setCash), arguments);
tx.params = unpacked.params;
tx.params[1] = abi.fix(tx.params[1], "hex");
return this.transact.apply(this, [tx].concat(unpacked.cb));
},

addCash: function (ID, amount, onSent, onSuccess, onFailed) {
var tx = clone(this.tx.cash.addCash);
var tx = clone(this.tx.Cash.addCash);
var unpacked = utils.unpack(ID, utils.labels(this.addCash), arguments);
tx.params = unpacked.params;
tx.params[1] = abi.fix(tx.params[1], "hex");
return this.transact.apply(this, [tx].concat(unpacked.cb));
},

initiateOwner: function (account, onSent, onSuccess, onFailed) {
// account: ethereum account
if (account && account.account) {
if (account.onSent) onSent = account.onSent;
if (account.onSuccess) onSuccess = account.onSuccess;
if (account.onFailed) onFailed = account.onFailed;
account = account.account;
}
var tx = clone(this.tx.cash.initiateOwner);
tx.params = account;
return this.transact(tx, onSent, onSuccess, onFailed);
getCashBalance: function (args) {
return this.Cash.balance(args);
},

// getCashBalance: function (account, callback) {
// // account: ethereum account
// var tx = clone(this.tx.cash.getCashBalance);
// tx.params = account || this.from;
// return this.fire(tx, callback);
// },

sendCash: function (to, value, onSent, onSuccess, onFailed) {
// to: ethereum account
// value: number -> fixed-point
Expand All @@ -57,7 +41,7 @@ module.exports = {
if (to.onFailed) onFailed = to.onFailed;
to = to.to;
}
var tx = clone(this.tx.cash.send);
var tx = clone(this.tx.Cash.send);
tx.params = [to, abi.fix(value, "hex")];
return this.transact(tx, onSent, onSuccess, onFailed);
},
Expand All @@ -74,29 +58,8 @@ module.exports = {
if (to.onFailed) onFailed = to.onFailed;
to = to.to;
}
var tx = clone(this.tx.cash.sendFrom);
var tx = clone(this.tx.Cash.sendFrom);
tx.params = [to, abi.fix(value, "hex"), from];
return this.transact(tx, onSent, onSuccess, onFailed);
},

depositEther: function (value, onSent, onSuccess, onFailed) {
// value: amount of ether to exchange for cash (in ETHER, not wei!)
if (value && value.value) {
if (value.onSent) onSent = value.onSent;
if (value.onSuccess) onSuccess = value.onSuccess;
if (value.onFailed) onFailed = value.onFailed;
value = value.value;
}
var tx = clone(this.tx.cash.depositEther);
tx.value = abi.prefix_hex(abi.bignum(value).mul(this.rpc.ETHER).toString(16));
return this.transact(tx, onSent, onSuccess, onFailed);
},

withdrawEther: function (to, value, onSent, onSuccess, onFailed) {
var tx = clone(this.tx.cash.withdrawEther);
var unpacked = utils.unpack(to, utils.labels(this.withdrawEther), arguments);
tx.params = unpacked.params;
tx.params[1] = abi.prefix_hex(abi.bignum(tx.params[1]).mul(this.rpc.ETHER).toString(16));
return this.transact.apply(this, [tx].concat(unpacked.cb));
}
};
25 changes: 0 additions & 25 deletions src/modules/closeMarket.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/modules/completeSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ var utils = require("../utilities");
module.exports = {

buyCompleteSets: function (market, amount, onSent, onSuccess, onFailed) {
var tx = clone(this.tx.completeSets.buyCompleteSets);
var tx = clone(this.tx.CompleteSets.buyCompleteSets);
var unpacked = utils.unpack(arguments[0], utils.labels(this.buyCompleteSets), arguments);
tx.params = unpacked.params;
tx.params[1] = abi.fix(tx.params[1], "hex");
return this.transact.apply(this, [tx].concat(unpacked.cb));
},

sellCompleteSets: function (market, amount, onSent, onSuccess, onFailed) {
var tx = clone(this.tx.completeSets.sellCompleteSets);
var tx = clone(this.tx.CompleteSets.sellCompleteSets);
var unpacked = utils.unpack(arguments[0], utils.labels(this.sellCompleteSets), arguments);
tx.params = unpacked.params;
tx.params[1] = abi.fix(tx.params[1], "hex");
Expand Down
8 changes: 4 additions & 4 deletions src/modules/compositeGetters.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
}
return orderBook;
}
var tx = clone(this.tx.compositeGetters.getOrderBook);
var tx = clone(this.tx.CompositeGetters.getOrderBook);
tx.params = marketID;
if (!utils.is_function(callback)) return getOrderBook(this.fire(tx));
this.fire(tx, function (orderArray) {
Expand All @@ -51,7 +51,7 @@ module.exports = {

getMarketInfo: function (market, callback) {
var self = this;
var tx = clone(this.tx.compositeGetters.getMarketInfo);
var tx = clone(this.tx.CompositeGetters.getMarketInfo);
var unpacked = utils.unpack(market, utils.labels(this.getMarketInfo), arguments);
tx.params = unpacked.params;
tx.timeout = 45000;
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = {
}
return marketsInfo;
}
var tx = clone(this.tx.compositeGetters.batchGetMarketInfo);
var tx = clone(this.tx.CompositeGetters.batchGetMarketInfo);
tx.params = [marketIDs];
if (!utils.is_function(callback)) {
return batchGetMarketInfo(this.fire(tx));
Expand All @@ -123,7 +123,7 @@ module.exports = {
if (!callback && utils.is_function(options.callback)) {
callback = options.callback;
}
var tx = clone(this.tx.compositeGetters.getMarketsInfo);
var tx = clone(this.tx.CompositeGetters.getMarketsInfo);
tx.params = [branch, offset, numMarketsToLoad];
tx.timeout = 240000;
if (!utils.is_function(callback)) {
Expand Down
39 changes: 27 additions & 12 deletions src/modules/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,50 @@ module.exports = {
bindContractMethod: function (contract, method) {
var self = this;
return function (args) {
var tx, params, cb, onSent, onSuccess, onFailed;
var tx, params, cb, i, onSent, onSuccess, onFailed;
tx = clone(self.tx[contract][method]);
if (!arguments) {
if (!tx.send) return self.fire(tx);
return self.transact(tx);
}
params = Array.prototype.slice.call(arguments);
if (!tx.send) {
if (utils.is_function(params[params.length - 1])) {
cb = params.pop();
if (params[0] !== undefined && params[0] !== null &&
params[0].constructor === Object) {
cb = params[0].callback || utils.pass;
if (tx.inputs && tx.inputs.length) {
tx.params = new Array(tx.inputs.length);
for (i = 0; i < tx.inputs.length; ++i) {
tx.params[i] = params[0][tx.inputs[i]];
}
}
} else {
if (utils.is_function(params[params.length - 1])) {
cb = params.pop();
}
tx.params = params;
}
tx.params = params;
return self.fire(tx, cb);
}
if (params[0] !== undefined && params[0] !== null &&
params[0].constructor === Object) {
onSent = params[0].onSent || utils.pass;
onSuccess = params[0].onSuccess || utils.pass;
onFailed = params[0].onFailed || utils.pass;
// need param names, order
return self.transact(tx, onSent, onSuccess, onFailed);
} else {
cb = [];
while (utils.is_function(params[params.length - 1])) {
cb.push(params.pop());
if (tx.inputs && tx.inputs.length) {
tx.params = new Array(tx.inputs.length);
for (i = 0; i < tx.inputs.length; ++i) {
tx.params[i] = params[0][tx.inputs[i]];
}
}
tx.params = params;
return self.transact.apply(self, [tx].concat(cb));
return self.transact(tx, onSent, onSuccess, onFailed);
}
cb = [];
while (utils.is_function(params[params.length - 1])) {
cb.push(params.pop());
}
tx.params = params;
return self.transact.apply(self, [tx].concat(cb));
};
},
bindContractAPI: function (methods) {
Expand Down
Loading

0 comments on commit a235ce7

Please sign in to comment.