-
Notifications
You must be signed in to change notification settings - Fork 0
/
ETHController_template.hbs
87 lines (79 loc) · 2.33 KB
/
ETHController_template.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const path = require("path");
const fs = require("fs");
const Web3 = require("web3");
const herePath = aPath => path.resolve(__dirname, aPath)
const conf = require(herePath("./config.json"));
const web3 = new Web3(new Web3.providers.HttpProvider(conf.eth.provider));
const Connector = require(herePath("./GenericETHConnector"));
/**
* @class
* @classdesc - interface to interact with ETH Connector for all methods
* */
class {{ contractName }}Controller{
/**
* @constructor
* @description initializes the connector, which will interact with SmartContract via web3
* */
constructor(){
this.config = JSON.parse(fs.readFileSync(herePath("./config.json")));
}
/**
* @function
* @instance
* @description Detects current network and instantiates web3 interface to it.
* @returns { Promise }
* */
detectNetwork(){
return web3.eth.net.getId().then((netId) => {
this.connector = new Connector(herePath("./contract.json"), netId);
}).catch(err => {
console.log(err)
});
}
/**
* @function
* @instance
* @description Deprecated name for #detectNetwork().
* @returns { Promise }
* */
connect(){
return detectNetwork();
}
{{#each abi}}
{{#ifEquals type "function"}}
{{#if constant }}
/**
* @function
* @instance
* @param { address } from - from address
{{#each inputs}}
* @param { {{type}} } {{name}}
{{/each}}
* @description Call {{name}}, does not execute a transaction.
* @returns { Promise }
* */
get_{{name}}(from{{inputSpread inputs}}){
return this.connector.read("{{name}}", from, [{{{inputList inputs}}}]);
}
{{else}}
/**
* @function
* @instance
* @param { address } from - from address
{{#if payable}}
* @param { Number } value - eth to be sent
{{/if}}
{{#each inputs}}
* @param { {{type}} } {{ name }}
{{/each}}
* @description Send transaction to {{name}}{{#if payable}}; real value is spent{{/if}}.
* @returns { Promise }
* */
post_{{name}}(from{{#if payable}}, value{{/if}}{{#each inputs}}, {{ name }}{{/each}}){
return this.connector.write("{{name}}", from, {{#if payable}}value{{else}}null{{/if}}, [{{{inputList inputs}}}]);
}
{{/if}}
{{/ifEquals}}
{{/each}}
}
module.exports = {{ contractName }}Controller;