[beta] Update comments and reg ABI (#4788)

* Update comments.

* Fix up new ABI.
This commit is contained in:
Arkadiy Paronyan
2017-03-06 20:18:57 +01:00
committed by GitHub
parent 3102cf7bc6
commit dc8bc8d8dd
3 changed files with 169 additions and 91 deletions

View File

@@ -41,11 +41,11 @@ ${convertContract(name, json, prefs)}
function convertContract(name, json, prefs) {
return `${prefs._pub ? "pub " : ""}struct ${name} {
contract: ethabi::Contract,
address: util::Address,
pub address: util::Address,
${prefs._explicit_do_call ? "" : `do_call: Box<Fn(util::Address, Vec<u8>) -> Result<Vec<u8>, String> + Send${prefs._sync ? " + Sync " : ""}+ 'static>,`}
}
impl ${name} {
pub fn new${prefs._explicit_do_call ? "" : "<F>"}(address: util::Address${prefs._explicit_do_call ? "" : `", do_call: F"`}) -> Self
pub fn new${prefs._explicit_do_call ? "" : "<F>"}(address: util::Address${prefs._explicit_do_call ? "" : `, do_call: F`}) -> Self
${prefs._explicit_do_call ? "" : `where F: Fn(util::Address, Vec<u8>) -> Result<Vec<u8>, String> + Send ${prefs._sync ? "+ Sync " : ""}+ 'static`} {
${name} {
contract: ethabi::Contract::new(ethabi::Interface::load(b"${JSON.stringify(json.filter(a => a.type == 'function')).replaceAll('"', '\\"')}").expect("JSON is autogenerated; qed")),
@@ -233,19 +233,23 @@ function convertFunction(json, _prefs) {
let prefs = {"_pub": true, "_": {"_client": {"string": true}, "_platform": {"string": true}}, "_sync": true};
// default contract json ABI
let jsonabi = [{"constant":true,"inputs":[],"name":"getValidators","outputs":[{"name":"","type":"address[]"}],"payable":false,"type":"function"}];
// default name
let name = 'Contract';
// parse command line options
for (let i = 1; i < process.argv.length; ++i) {
let arg = process.argv[i];
if (arg.indexOf("--jsonabi") == 0) {
if (arg.indexOf("--jsonabi=") == 0) {
jsonabi = arg.slice(10);
if (fs.existsSync(jsonabi)) {
jsonabi = JSON.parse(fs.readFileSync(jsonabi).toString());
}
} else if (arg.indexOf("--explicit-do-call") == 0) {
prefs._explicit_do_call = true;
} else if (arg.indexOf("--name=") == 0) {
name = arg.slice(7);
}
}
let out = makeContractFile("Contract", jsonabi, prefs);
let out = makeContractFile(name, jsonabi, prefs);
console.log(`${out}`);