mm_contract 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/index.js +5 -22
- package/lib/admin.js +17 -0
- package/lib/contract.js +24 -0
- package/lib/eth.js +436 -0
- package/lib/eth_ext.js +290 -0
- package/package.json +13 -5
- package/tool/contract/index.js +132 -0
- package/tool/contract/tool.json +111 -0
- package/.gitattributes +0 -2
- package/app/ap.sol +0 -26
- package/app/test.sol +0 -463
- package/app/token.sol +0 -260
- package/demo/abi/auction.json +0 -1168
- package/demo/abi/bep20.json +0 -533
- package/demo/abi/blindbox.json +0 -767
- package/demo/abi/erc1155.json +0 -833
- package/demo/abi/erc721s.json +0 -1393
- package/demo/abi/exchange.json +0 -408
- package/demo/abi/invite.json +0 -605
- package/demo/abi/itemsell.json +0 -420
- package/demo/abi/nftmarket.json +0 -747
- package/demo/abi/plant.json +0 -1093
- package/demo/abi/sharepool.json +0 -773
- package/demo/abi/tokenmarket.json +0 -174
- package/demo/abi/tokensell.json +0 -465
- package/demo/abi/vipcard.json +0 -86
- package/demo/abi/vipshop.json +0 -303
- package/demo/index.js +0 -63
- package/demo/index_2.js +0 -31
- package/demo/test.js +0 -65
- package/demo/test_abi.js +0 -448
- package/mm_eth.js +0 -720
- package/sol/assets.sol +0 -2
- package/sol/erc20.sol +0 -23
- package/sol/erc721.sol +0 -40
- package/sol/ownable.sol +0 -42
- package/sol/safeMath.sol +0 -118
- package/sol//345/220/210/347/272/246/345/234/260/345/235/200.txt +0 -2
- package/test.js +0 -13
- /package/{mm_tron.js → lib/tron.js} +0 -0
package/lib/eth_ext.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const Contract = require("../eth.js");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 转账
|
|
7
|
+
* @param {String} type 类型
|
|
8
|
+
* @param {String} name 名称
|
|
9
|
+
* @param {String} method 合约方法
|
|
10
|
+
* @param {Number} value 转账数量
|
|
11
|
+
* @param {Array} 合约传参
|
|
12
|
+
* @return {Object} 成功返回转账结果, 否则返回空
|
|
13
|
+
*/
|
|
14
|
+
Eth.prototype.sendS = async function(type, name, method, value, ...param) {
|
|
15
|
+
let address_my = this.web3.eth.defaultAccount || this.address;
|
|
16
|
+
|
|
17
|
+
if (!this[type]) {
|
|
18
|
+
this._logger.error("合约类型不正确");
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
if (!this[type][name]) {
|
|
22
|
+
this._logger.error("合约不正确");
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
if (!this[type][name].contract.methods[method]) {
|
|
26
|
+
this._logger.error("函数不存在!");
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let data = await this[type][name].contract.methods[method](...param).encodeABI();
|
|
31
|
+
let contract_address = this[type][name].address;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
let nonce = await this.getNonce();
|
|
35
|
+
|
|
36
|
+
let rawTx = {
|
|
37
|
+
// from: address_my,
|
|
38
|
+
nonce,
|
|
39
|
+
// eth用 0x14F46B0400, bsc用 0x12A05F200
|
|
40
|
+
gasPrice: "0x12A05F200",
|
|
41
|
+
gasLimit: '0x249F0',
|
|
42
|
+
to: contract_address,
|
|
43
|
+
// 调用receiveEth 给合约转入0.1eth ,如果调用合约方法不给合约转入eth,这个值是0
|
|
44
|
+
value: value ? this.toChage16(value) : '0x0',
|
|
45
|
+
// 这个数据需要自己拼接,在gitee/gkai/metamask里面有方法(通过encodeABI可以不用自己拼接了)
|
|
46
|
+
data
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// $.log.info("数据", rawTx);
|
|
50
|
+
let sign_data = await this.web3.eth.accounts.signTransaction(rawTx, this.config.private_key);
|
|
51
|
+
if (!sign_data) {
|
|
52
|
+
this._logger.error("签名失败", rawTx, err);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
// $.log.info("签名", sign_data);
|
|
56
|
+
// $.sleep(1000);
|
|
57
|
+
let tx = null;
|
|
58
|
+
try {
|
|
59
|
+
tx = await this.web3.eth.sendSignedTransaction(sign_data.rawTransaction);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
this._logger.error("链上交易超时", rawTx, err);
|
|
62
|
+
}
|
|
63
|
+
// $.log.info("广播", tx);
|
|
64
|
+
if (tx) {
|
|
65
|
+
if (!tx.status) {
|
|
66
|
+
this.nonce = 0;
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
this.nonce -= 1
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this._logger.debug('send res', name, tx);
|
|
74
|
+
return tx;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/** 追加 **/
|
|
80
|
+
/**
|
|
81
|
+
* call obj
|
|
82
|
+
* @param {String} name Login Method
|
|
83
|
+
* @param {String} method ABI method
|
|
84
|
+
* @param {Array} keys object prop
|
|
85
|
+
* @param {Array} param parameter set
|
|
86
|
+
* @return {String} return address
|
|
87
|
+
*/
|
|
88
|
+
Eth.prototype.callObj = async function(type, name, method, keys, ...param) {
|
|
89
|
+
this._logger.debug("call req", type, name, method, ...param);
|
|
90
|
+
try {
|
|
91
|
+
let res = await this[type][name].contract.methods[method](...param).call({
|
|
92
|
+
from: this.address
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
this._logger.error(method, err)
|
|
96
|
+
}
|
|
97
|
+
let arr = res.split('_');
|
|
98
|
+
let obj = {};
|
|
99
|
+
for(let i = 0; i < keys.length; i++){
|
|
100
|
+
obj[keys[i]] = arr.length > i ? arr[i] : 0;
|
|
101
|
+
}
|
|
102
|
+
this._logger.debug("call res", name, method, obj);
|
|
103
|
+
return obj;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* call list
|
|
108
|
+
* @param {String} name Login Method
|
|
109
|
+
* @param {String} method ABI method
|
|
110
|
+
* @param {Array} keys object prop
|
|
111
|
+
* @param {Array} param parameter set
|
|
112
|
+
* @return {String} return address
|
|
113
|
+
*/
|
|
114
|
+
Eth.prototype.callList = async function(type, name, method, keys, ...param) {
|
|
115
|
+
this._logger.debug("call req", type, name, method, ...param);
|
|
116
|
+
try {
|
|
117
|
+
let res = await this[type][name].contract.methods[method](...param).call({
|
|
118
|
+
from: this.address
|
|
119
|
+
});
|
|
120
|
+
} catch (err) {
|
|
121
|
+
this._logger.error(method, err)
|
|
122
|
+
}
|
|
123
|
+
let list = res.map((o) => {
|
|
124
|
+
let arr = o.split('_');
|
|
125
|
+
let obj = {};
|
|
126
|
+
for(let i = 0; i < keys.length; i++){
|
|
127
|
+
obj[keys[i]] = arr.length > i ? arr[i] : 0;
|
|
128
|
+
}
|
|
129
|
+
return obj
|
|
130
|
+
});
|
|
131
|
+
this._logger.debug("call res", name, method, list);
|
|
132
|
+
return list;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Add event
|
|
137
|
+
* @param {Function} name event name
|
|
138
|
+
* @param {Function} func event method
|
|
139
|
+
* @returns {Funtion} this event function key
|
|
140
|
+
*/
|
|
141
|
+
Eth.prototype.addEvent = function(func, name) {
|
|
142
|
+
if (!name) {
|
|
143
|
+
this.list_count++;
|
|
144
|
+
name = this.list_count;
|
|
145
|
+
}
|
|
146
|
+
this.list_event[name] = func;
|
|
147
|
+
return name;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Delete event
|
|
152
|
+
* @param {Function} name event name
|
|
153
|
+
*/
|
|
154
|
+
Eth.prototype.delEvent = function(name) {
|
|
155
|
+
delete this.list_event[name];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* execute provider
|
|
160
|
+
* @param {Object} provider
|
|
161
|
+
*/
|
|
162
|
+
Eth.prototype.subscribeEvent = function(provider) {
|
|
163
|
+
if (!provider) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Subscribe to accounts change
|
|
167
|
+
provider.on("accountsChanged", (accounts) => {
|
|
168
|
+
this.event("accountsChanged", accounts)
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Subscribe to chainId change
|
|
172
|
+
provider.on("chainChanged", (chainId) => {
|
|
173
|
+
this.event("chainChanged", null, this.toChage10(chainId, 1))
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* This event is fired when a transaction is initiated
|
|
178
|
+
*/
|
|
179
|
+
provider.on("session_update", async (error, payload) => {
|
|
180
|
+
if (error) {
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
let {
|
|
184
|
+
chainId,
|
|
185
|
+
accounts
|
|
186
|
+
} = payload.params[0];
|
|
187
|
+
this.event("session_update", accounts, this.toChage10(chainId, 1));
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* when connected
|
|
192
|
+
*/
|
|
193
|
+
provider.on("connect", (error, payload) => {
|
|
194
|
+
if (error) {
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
if (!payload) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
let {
|
|
201
|
+
chainId,
|
|
202
|
+
accounts
|
|
203
|
+
} = payload;
|
|
204
|
+
this.event('connect', accounts, this.toChage10(chainId, 1));
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* when disconnected
|
|
209
|
+
*/
|
|
210
|
+
provider.on("disconnect", (error, payload) => {
|
|
211
|
+
if (error) {
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
this.event('disconnect');
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Web3 签名加密
|
|
220
|
+
* @param {String} content 签名内容
|
|
221
|
+
* @param {String} address 签名地址
|
|
222
|
+
* @param {Function} func 回调函数(可选)
|
|
223
|
+
*/
|
|
224
|
+
Eth.prototype.sign = async function(content, address, func) {
|
|
225
|
+
let ret = null;
|
|
226
|
+
if (func) {
|
|
227
|
+
this.web3.eth.sign(content, address, func);
|
|
228
|
+
} else {
|
|
229
|
+
ret = await this.web3.eth.sign(content, address);
|
|
230
|
+
}
|
|
231
|
+
return ret;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
Eth.prototype.getBalance = async function(address) {
|
|
235
|
+
let {
|
|
236
|
+
chain_accuracy
|
|
237
|
+
} = this.config;
|
|
238
|
+
let y = Math.pow(10, chain_accuracy);
|
|
239
|
+
|
|
240
|
+
if (!this.default_address) {
|
|
241
|
+
await this.getAccounts();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!address) {
|
|
245
|
+
address = this.default_address;
|
|
246
|
+
}
|
|
247
|
+
// 查询余额
|
|
248
|
+
let num_str = await this.web3.eth.getBalance(address);
|
|
249
|
+
// 转为大数字类型
|
|
250
|
+
let num_b = new BigNumber(num_str);
|
|
251
|
+
// 除以小数位
|
|
252
|
+
let balance = num_b.div(y).toNumber();
|
|
253
|
+
// 保存余额
|
|
254
|
+
this.balance = balance;
|
|
255
|
+
return balance;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 获取以太网上的账户
|
|
260
|
+
* @return {Array} 账户数组
|
|
261
|
+
*/
|
|
262
|
+
Eth.prototype.getAccount = async function() {
|
|
263
|
+
this.default_address = this.web3.eth.defaultAccount;
|
|
264
|
+
return this.default_address;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 获取以太网上的账户
|
|
269
|
+
* @return {Array} 账户数组
|
|
270
|
+
*/
|
|
271
|
+
Eth.prototype.getAccounts = async function() {
|
|
272
|
+
let accounts = await this.web3.eth.getAccounts();
|
|
273
|
+
if (accounts.length) {
|
|
274
|
+
this.web3.eth.defaultAccount = accounts[0];
|
|
275
|
+
this.default_address = this.web3.eth.defaultAccount;
|
|
276
|
+
}
|
|
277
|
+
return accounts;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 加载ABI
|
|
282
|
+
* @param {String} path 地址
|
|
283
|
+
* @return {String} 加载成功返回true
|
|
284
|
+
*/
|
|
285
|
+
Eth.prototype.loadAbi = function(abi) {
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
module.exports = {};
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_contract",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "这是超级美眉智能合约调用辅助模块,用于快速发布合约和调用区块链ABI方法,适用于eth和tron。",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"lib",
|
|
9
|
+
"mm_eth.js",
|
|
10
|
+
"mm_tron.js",
|
|
11
|
+
"tool"
|
|
12
|
+
],
|
|
6
13
|
"scripts": {
|
|
7
14
|
"test": "node test.js",
|
|
8
15
|
"dev": "nodemon ./demo/index.js"
|
|
@@ -28,8 +35,8 @@
|
|
|
28
35
|
"调用ABI",
|
|
29
36
|
"Contract"
|
|
30
37
|
],
|
|
31
|
-
"layer": "
|
|
32
|
-
"group": "
|
|
38
|
+
"layer": "util",
|
|
39
|
+
"group": "io",
|
|
33
40
|
"author": "邱文武(qiuwenwu)",
|
|
34
41
|
"license": "ISC",
|
|
35
42
|
"bugs": {
|
|
@@ -38,9 +45,10 @@
|
|
|
38
45
|
"homepage": "https://gitee.com/qiuwenwu91/mm_contract#readme",
|
|
39
46
|
"dependencies": {
|
|
40
47
|
"bignumber": "^1.1.0",
|
|
41
|
-
"
|
|
48
|
+
"mm_admin": "^1.2.2",
|
|
49
|
+
"web3": "^4.16.0"
|
|
42
50
|
},
|
|
43
51
|
"devDependencies": {
|
|
44
|
-
"mm_logs": "^1.
|
|
52
|
+
"mm_logs": "^1.7.2"
|
|
45
53
|
}
|
|
46
54
|
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* contract —— 链上合约账户与调用工具
|
|
4
|
+
* 复用模块合约类(内部按 chain 分派到 eth/tron 实现),能力层不接触 web3 细节。
|
|
5
|
+
* 说明:模块的 web3 连接由 init()/login() 建立,所有动作都先完成连接再取数。
|
|
6
|
+
*/
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
let { mm_contract: Contract } = require('../../index.js');
|
|
9
|
+
|
|
10
|
+
/** 合约分组名:call 按模块约定以「分组 → 别名 → { address, contract }」注册合约 */
|
|
11
|
+
const GROUP = 'tool_contract';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 构建模块配置
|
|
15
|
+
* @param {object} p 参数
|
|
16
|
+
* @returns {object} 模块配置
|
|
17
|
+
*/
|
|
18
|
+
function _config(p) {
|
|
19
|
+
let chainId = Number(p.chain_id || 97);
|
|
20
|
+
let cfg = { chainId: chainId, chain_accuracy: 18 };
|
|
21
|
+
if (p.rpc) {
|
|
22
|
+
let map = {};
|
|
23
|
+
map[chainId] = p.rpc;
|
|
24
|
+
cfg.rpc = map;
|
|
25
|
+
}
|
|
26
|
+
if (p.default_account) {
|
|
27
|
+
cfg.defaultAccount = p.default_account;
|
|
28
|
+
}
|
|
29
|
+
return cfg;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 新建合约实例
|
|
34
|
+
* @param {object} p 参数
|
|
35
|
+
* @returns {object} 合约实例
|
|
36
|
+
*/
|
|
37
|
+
function _instance(p) {
|
|
38
|
+
return new Contract(_config(p), p.chain === 'tron' ? 'tron' : 'eth');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 建立连接(默认账户由此就绪)
|
|
43
|
+
* @param {object} inst 合约实例
|
|
44
|
+
* @returns {Promise<object>} 合约实例
|
|
45
|
+
*/
|
|
46
|
+
async function _connect(inst) {
|
|
47
|
+
if (typeof inst.init === 'function') {
|
|
48
|
+
await inst.init();
|
|
49
|
+
} else if (typeof inst.login === 'function') {
|
|
50
|
+
await inst.login();
|
|
51
|
+
}
|
|
52
|
+
return inst;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 读取 ABI
|
|
57
|
+
* @param {string} abi ABI JSON 字符串或文件路径
|
|
58
|
+
* @returns {Array} ABI 数组
|
|
59
|
+
*/
|
|
60
|
+
function _abi(abi) {
|
|
61
|
+
if (!abi) throw new TypeError('abi 不能为空');
|
|
62
|
+
let text = abi.trim()[0] === '[' ? abi : fs.readFileSync(abi, 'utf8');
|
|
63
|
+
return JSON.parse(text);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 执行合约工具动作
|
|
68
|
+
* @param {object} params 工具参数
|
|
69
|
+
* @param {object} ctx 上下文
|
|
70
|
+
* @param {object} options 选项
|
|
71
|
+
* @returns {Promise<object>} 执行结果
|
|
72
|
+
*/
|
|
73
|
+
async function main(params, ctx, options) {
|
|
74
|
+
void options;
|
|
75
|
+
let p = params || {};
|
|
76
|
+
let action = p.action || 'account';
|
|
77
|
+
/**
|
|
78
|
+
* 写入上下文输出并返回结果
|
|
79
|
+
* @param {object} data 输出数据
|
|
80
|
+
* @returns {object} 输出数据
|
|
81
|
+
*/
|
|
82
|
+
const done = (data) => { ctx.output = data; return data; };
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
if (action === 'account') {
|
|
86
|
+
let inst = await _connect(_instance(p));
|
|
87
|
+
let address = await inst.getAccount();
|
|
88
|
+
if (!address) return done({ code: 10002, msg: '取默认账户失败:节点未返回账户且未配置 default_account' });
|
|
89
|
+
return done({ code: 0, msg: '成功', address: String(address) });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (action === 'balance') {
|
|
93
|
+
let inst = await _connect(_instance(p));
|
|
94
|
+
let balance = await inst.getBalance(p.address || undefined);
|
|
95
|
+
if (typeof balance !== 'number' || Number.isNaN(balance)) {
|
|
96
|
+
return done({ code: 10002, msg: '余额查询无有效返回:请确认 rpc 可达、address 合法' });
|
|
97
|
+
}
|
|
98
|
+
return done({ code: 0, msg: '成功', address: p.address || '', balance: String(balance) });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (action === 'sign') {
|
|
102
|
+
if (!p.message) throw new TypeError('message 不能为空');
|
|
103
|
+
let inst = await _connect(_instance(p));
|
|
104
|
+
let signature = await inst.sign(p.message, p.address || inst.address);
|
|
105
|
+
if (!signature) return done({ code: 10002, msg: '签名无返回:需节点托管并解锁该账户私钥' });
|
|
106
|
+
return done({ code: 0, msg: '成功', message: p.message, signature: signature });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (action === 'call') {
|
|
110
|
+
if (!p.contract) throw new TypeError('contract 不能为空');
|
|
111
|
+
if (!p.method) throw new TypeError('method 不能为空');
|
|
112
|
+
let abi = _abi(p.abi);
|
|
113
|
+
let inst = await _connect(_instance(p));
|
|
114
|
+
let alias = p.name || 'main';
|
|
115
|
+
let contract = inst.new(alias, abi, p.contract);
|
|
116
|
+
inst[GROUP] = {};
|
|
117
|
+
inst[GROUP][alias] = { address: p.contract, contract: contract };
|
|
118
|
+
let args = Array.isArray(p.args) ? p.args : [];
|
|
119
|
+
let result = await inst.call(GROUP, alias, p.method, 0, ...args);
|
|
120
|
+
if (result === undefined || result === null) {
|
|
121
|
+
return done({ code: 10002, msg: '合约调用无返回:请确认 rpc 可达、方法名与 abi 匹配、参数类型正确' });
|
|
122
|
+
}
|
|
123
|
+
return done({ code: 0, msg: '调用完成', contract: p.contract, method: p.method, result: result });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return done({ code: 10001, msg: '不支持的操作: ' + action });
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return done({ code: 10000, msg: '执行失败:' + error.message, error: { name: error.name, message: error.message } });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { main };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "contract",
|
|
3
|
+
"title": "链上合约账户与调用",
|
|
4
|
+
"description": "基于 mm_contract 的链上合约辅助能力:连接节点后取默认账户、按地址查余额、对消息签名、调用合约只读方法。适用场景:查询钱包余额、确认默认账户、签名后转发、读合约视图方法。工作流提示:chain 选 eth/tron;balance/call 需传 rpc;只读调用用 call,写操作请在业务侧另走交易流程。",
|
|
5
|
+
"category": "区块链",
|
|
6
|
+
"group": "blockchain",
|
|
7
|
+
"type": "function",
|
|
8
|
+
"main": "./index.js",
|
|
9
|
+
"params": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"action": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "操作类型: account(默认账户)/balance(查余额)/sign(消息签名)/call(合约只读调用)",
|
|
15
|
+
"enum": [
|
|
16
|
+
"account",
|
|
17
|
+
"balance",
|
|
18
|
+
"sign",
|
|
19
|
+
"call"
|
|
20
|
+
],
|
|
21
|
+
"default": "account"
|
|
22
|
+
},
|
|
23
|
+
"chain": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "链类型: eth/tron,缺省 eth",
|
|
26
|
+
"enum": [
|
|
27
|
+
"eth",
|
|
28
|
+
"tron"
|
|
29
|
+
],
|
|
30
|
+
"default": "eth"
|
|
31
|
+
},
|
|
32
|
+
"chain_id": {
|
|
33
|
+
"type": "number",
|
|
34
|
+
"description": "链 ID,缺省 97(BSC 测试网)",
|
|
35
|
+
"default": 97
|
|
36
|
+
},
|
|
37
|
+
"rpc": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "节点 RPC 地址,缺省用模块内置链表"
|
|
40
|
+
},
|
|
41
|
+
"default_account": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"description": "默认账户地址,缺省用模块内置地址"
|
|
44
|
+
},
|
|
45
|
+
"address": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "查询/签名地址(balance 可选,缺省取默认账户)"
|
|
48
|
+
},
|
|
49
|
+
"message": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "待签消息(sign 必填)"
|
|
52
|
+
},
|
|
53
|
+
"contract": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"description": "合约地址(call 必填)"
|
|
56
|
+
},
|
|
57
|
+
"name": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "合约别名(call 可选),缺省 main"
|
|
60
|
+
},
|
|
61
|
+
"abi": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "合约 ABI(JSON 字符串或 ABI 文件路径,call 必填)"
|
|
64
|
+
},
|
|
65
|
+
"method": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"description": "方法名(call 必填)"
|
|
68
|
+
},
|
|
69
|
+
"args": {
|
|
70
|
+
"type": "array",
|
|
71
|
+
"description": "方法参数(call 可选)"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"required": [
|
|
75
|
+
"action"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"returns": {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"properties": {
|
|
81
|
+
"code": {
|
|
82
|
+
"type": "number",
|
|
83
|
+
"description": "0 表示成功,1xxxx 表示业务/执行异常"
|
|
84
|
+
},
|
|
85
|
+
"msg": {
|
|
86
|
+
"type": "string",
|
|
87
|
+
"description": "结果描述"
|
|
88
|
+
},
|
|
89
|
+
"address": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"description": "账户地址"
|
|
92
|
+
},
|
|
93
|
+
"balance": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"description": "余额"
|
|
96
|
+
},
|
|
97
|
+
"signature": {
|
|
98
|
+
"type": "string",
|
|
99
|
+
"description": "签名结果(sign)"
|
|
100
|
+
},
|
|
101
|
+
"result": {
|
|
102
|
+
"description": "调用返回值(call)"
|
|
103
|
+
},
|
|
104
|
+
"error": {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"description": "异常对象 { name, message }"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"handler": "manager"
|
|
111
|
+
}
|
package/.gitattributes
DELETED
package/app/ap.sol
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
pragma solidity ^0.4.0;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @dev ERC20 Token abstract constract.
|
|
5
|
-
*/
|
|
6
|
-
contract ERC20Token {
|
|
7
|
-
function transferFrom(address, address, uint256) public returns (bool);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
contract Blank {
|
|
11
|
-
/**
|
|
12
|
-
* @dev calls the ERC20 token's transferFrom function
|
|
13
|
-
* @param _token address The address of ERC20 token.
|
|
14
|
-
* @param _dsts address The addresses which be air dropped.
|
|
15
|
-
* @param _values uint256 The token values that each address will receive.
|
|
16
|
-
*/
|
|
17
|
-
function transfer(address _token, address[] _dsts, uint256[] _values)
|
|
18
|
-
public
|
|
19
|
-
payable
|
|
20
|
-
{
|
|
21
|
-
ERC20Token token = ERC20Token(_token);
|
|
22
|
-
for (uint256 i = 0; i < _dsts.length; i++) {
|
|
23
|
-
token.transferFrom(msg.sender, _dsts[i], _values[i]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|