mm_contract 1.0.2 → 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/index.js CHANGED
@@ -1,4 +1,5 @@
1
- 'use strict';
2
- const mm_contract = require('./lib/mm_contract');
1
+ const Contract = require('./lib/contract.js');
3
2
 
4
- module.exports = { mm_contract };
3
+ module.exports = {
4
+ Contract
5
+ };
package/lib/admin.js ADDED
@@ -0,0 +1,17 @@
1
+ const { reg } = require('mm_admin');
2
+ const Contract = require('../contract.js');
3
+
4
+ let admin = reg('contract');
5
+ admin.setClass(Contract);
6
+
7
+ /**
8
+ * 合约管理员
9
+ */
10
+ function contractAdmin(scope, config) {
11
+ return admin.get(scope || 'os', config);
12
+ }
13
+
14
+ module.exports = {
15
+ admin,
16
+ contractAdmin
17
+ };
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
- let mm_eth = require('../mm_eth.js');
3
- let mm_tron = require('../mm_tron.js');
2
+ let Eth = require('../eth.js');
3
+ let Tron = require('../tron.js');
4
4
 
5
5
  /**
6
6
  * 合约分发类,按链类型返回对应实现实例。
7
7
  */
8
- class mm_contract {
8
+ class Contract {
9
9
  /**
10
10
  * 按链类型创建合约实例
11
11
  * @param {Object} config 配置参数
@@ -14,11 +14,11 @@ class mm_contract {
14
14
  */
15
15
  constructor(config, type) {
16
16
  if (type == "tron") {
17
- return new mm_tron(config);
17
+ return new Tron(config);
18
18
  } else {
19
- return new mm_eth(config);
19
+ return new Eth(config);
20
20
  }
21
21
  }
22
22
  }
23
23
 
24
- module.exports = mm_contract;
24
+ module.exports = Contract;
@@ -1,7 +1,7 @@
1
1
  const Web3 = require("web3");
2
2
  const BigNumber = require("bignumber.js");
3
3
 
4
- class MM_eth {
4
+ class Eth {
5
5
  /**
6
6
  * 创建以太坊合约实例
7
7
  * @param {Object} config - 配置参数
@@ -69,7 +69,7 @@ class MM_eth {
69
69
  /**
70
70
  * 设置日志记录器
71
71
  * @param {Object} logger 日志记录器(需实现 debug/info/warn/error)
72
- * @returns {MM_eth} 当前实例
72
+ * @returns {Eth} 当前实例
73
73
  */
74
74
  setLogger(logger) {
75
75
  if (logger) {
@@ -90,7 +90,7 @@ class MM_eth {
90
90
  /**
91
91
  * 新建驱动
92
92
  */
93
- MM_eth.prototype.newProvider = function() {
93
+ Eth.prototype.newProvider = function() {
94
94
  let host = this.config.rpc[this.config.chainId];
95
95
  // 使用web3来进行区块链接口的调用
96
96
  let web3 = new Web3();
@@ -104,7 +104,7 @@ MM_eth.prototype.newProvider = function() {
104
104
  * @param {String} way 登录
105
105
  * @return {String} 地址
106
106
  */
107
- MM_eth.prototype.login = async function(way) {
107
+ Eth.prototype.login = async function(way) {
108
108
  if (!this._provider) {
109
109
  this._provider = this.newProvider();
110
110
  }
@@ -126,7 +126,7 @@ MM_eth.prototype.login = async function(way) {
126
126
  * 构建连接
127
127
  * @param {Object} Type
128
128
  */
129
- MM_eth.prototype.link = async function(type) {
129
+ Eth.prototype.link = async function(type) {
130
130
  let dict = this[type];
131
131
  let abi = this.config[type + "_abi"];
132
132
  for (let k in dict) {
@@ -138,7 +138,7 @@ MM_eth.prototype.link = async function(type) {
138
138
  /**
139
139
  * 初始化
140
140
  */
141
- MM_eth.prototype.initAbi = async function() {
141
+ Eth.prototype.initAbi = async function() {
142
142
  for (let k in this.config) {
143
143
  if (k.indexOf("_abi") !== -1) {
144
144
  await this.link(k.replace("_abi", ""));
@@ -151,7 +151,7 @@ MM_eth.prototype.initAbi = async function() {
151
151
  * @param {String} way 登录方式
152
152
  * @return {String} 返回地址
153
153
  */
154
- MM_eth.prototype.init = async function(way) {
154
+ Eth.prototype.init = async function(way) {
155
155
  await this.login(way);
156
156
  await this.initAbi();
157
157
  return this.web3;
@@ -166,7 +166,7 @@ MM_eth.prototype.init = async function(way) {
166
166
  * @param {Array} param 参数集合
167
167
  * @return {String} 返回地址
168
168
  */
169
- MM_eth.prototype.send = async function(type, name, method, value, ...param) {
169
+ Eth.prototype.send = async function(type, name, method, value, ...param) {
170
170
  this._logger.debug("send req", type, name, method, value, ...param);
171
171
  try {
172
172
  let res = await this[type][name].contract.methods[method](...param).send({
@@ -190,7 +190,7 @@ MM_eth.prototype.send = async function(type, name, method, value, ...param) {
190
190
  * @param {Array} param 参数集合
191
191
  * @return {String} 返回地址
192
192
  */
193
- MM_eth.prototype.call = async function(type, name, method, value, ...param) {
193
+ Eth.prototype.call = async function(type, name, method, value, ...param) {
194
194
  if (!this.address) {
195
195
  await this.init();
196
196
  }
@@ -213,7 +213,7 @@ MM_eth.prototype.call = async function(type, name, method, value, ...param) {
213
213
  * @param {String} accounts 账号组
214
214
  * @param {Number} chainId 区块链频道
215
215
  */
216
- MM_eth.prototype.eventAfter = function(name, accounts, chainId) {
216
+ Eth.prototype.eventAfter = function(name, accounts, chainId) {
217
217
  // this._logger.debug(name);
218
218
  };
219
219
 
@@ -223,7 +223,7 @@ MM_eth.prototype.eventAfter = function(name, accounts, chainId) {
223
223
  * @param {String} accounts 账号组
224
224
  * @param {Number} chainId 区块链频道
225
225
  */
226
- MM_eth.prototype.event = function(name, accounts, chainId) {
226
+ Eth.prototype.event = function(name, accounts, chainId) {
227
227
  this._logger.debug("event:", name, accounts, chainId);
228
228
  if (accounts && accounts.length) {
229
229
  this.address = this._provider.selectedAddress || accounts[0];
@@ -274,7 +274,7 @@ MM_eth.prototype.event = function(name, accounts, chainId) {
274
274
  * 执行供应器
275
275
  * @param {Object} provider
276
276
  */
277
- MM_eth.prototype.subscribeEvent = function(provider) {
277
+ Eth.prototype.subscribeEvent = function(provider) {
278
278
  if (!provider) {
279
279
  return;
280
280
  }
@@ -336,7 +336,7 @@ MM_eth.prototype.subscribeEvent = function(provider) {
336
336
  * @param {Number} map 精度
337
337
  * @return {String} 转换结果
338
338
  */
339
- MM_eth.prototype.toChage10 = function(value, map) {
339
+ Eth.prototype.toChage10 = function(value, map) {
340
340
  if (value) {
341
341
  return parseInt(value.replace('0x', ''), 16) / (map || this.config.precision);
342
342
  } else {
@@ -351,7 +351,7 @@ MM_eth.prototype.toChage10 = function(value, map) {
351
351
  * @param {Array} abi ABI方法集合
352
352
  * @return {Object} 返回连接后的对象
353
353
  */
354
- MM_eth.prototype.new = function(name, abi, address) {
354
+ Eth.prototype.new = function(name, abi, address) {
355
355
  if (!this[name]) {
356
356
  this[name] = new this.web3.eth.Contract(abi, address);
357
357
  }
@@ -364,7 +364,7 @@ MM_eth.prototype.new = function(name, abi, address) {
364
364
  * @param {Number} map 精度
365
365
  * @return {String} 转换结果
366
366
  */
367
- MM_eth.prototype.toChage16 = function(num, map) {
367
+ Eth.prototype.toChage16 = function(num, map) {
368
368
  if (typeof(num) === "string") {
369
369
  return num;
370
370
  }
@@ -376,7 +376,7 @@ MM_eth.prototype.toChage16 = function(num, map) {
376
376
  * @param {String} value 需要补零的字符串
377
377
  * @return {String} 补零后的字符串
378
378
  */
379
- MM_eth.prototype.fullZore = function(value) {
379
+ Eth.prototype.fullZore = function(value) {
380
380
  let len = 64 - value.length;
381
381
  let val = "";
382
382
 
@@ -393,7 +393,7 @@ MM_eth.prototype.fullZore = function(value) {
393
393
  * @param {Array} param 请求参数集合
394
394
  * @return {Object} 返回参数
395
395
  */
396
- MM_eth.prototype.toParam = function(name, ...param) {
396
+ Eth.prototype.toParam = function(name, ...param) {
397
397
  let code = this.methods[name];
398
398
  let data = code;
399
399
  for (let i = 0; i < param.length; i++) {
@@ -416,7 +416,7 @@ MM_eth.prototype.toParam = function(name, ...param) {
416
416
  /**
417
417
  * 获取 nonce
418
418
  */
419
- MM_eth.prototype.getNonce = async function() {
419
+ Eth.prototype.getNonce = async function() {
420
420
  let nonce_online = await this.web3.eth.getTransactionCount(this.web3.eth.defaultAccount || this.address);
421
421
  let key = "wr_nonce";
422
422
  let nonce = this.nonce;
@@ -432,5 +432,5 @@ MM_eth.prototype.getNonce = async function() {
432
432
  return nonce;
433
433
  };
434
434
 
435
- module.exports = MM_eth;
436
- require("./lib/mm_eth_ext.js");
435
+ module.exports = Eth;
436
+ require("./lib/eth_ext.js");
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const MM_eth = require("../mm_eth.js");
2
+ const Contract = require("../eth.js");
3
3
 
4
4
 
5
5
  /**
@@ -11,7 +11,7 @@ const MM_eth = require("../mm_eth.js");
11
11
  * @param {Array} 合约传参
12
12
  * @return {Object} 成功返回转账结果, 否则返回空
13
13
  */
14
- MM_eth.prototype.sendS = async function(type, name, method, value, ...param) {
14
+ Eth.prototype.sendS = async function(type, name, method, value, ...param) {
15
15
  let address_my = this.web3.eth.defaultAccount || this.address;
16
16
 
17
17
  if (!this[type]) {
@@ -85,7 +85,7 @@ MM_eth.prototype.sendS = async function(type, name, method, value, ...param) {
85
85
  * @param {Array} param parameter set
86
86
  * @return {String} return address
87
87
  */
88
- MM_eth.prototype.callObj = async function(type, name, method, keys, ...param) {
88
+ Eth.prototype.callObj = async function(type, name, method, keys, ...param) {
89
89
  this._logger.debug("call req", type, name, method, ...param);
90
90
  try {
91
91
  let res = await this[type][name].contract.methods[method](...param).call({
@@ -111,7 +111,7 @@ MM_eth.prototype.callObj = async function(type, name, method, keys, ...param) {
111
111
  * @param {Array} param parameter set
112
112
  * @return {String} return address
113
113
  */
114
- MM_eth.prototype.callList = async function(type, name, method, keys, ...param) {
114
+ Eth.prototype.callList = async function(type, name, method, keys, ...param) {
115
115
  this._logger.debug("call req", type, name, method, ...param);
116
116
  try {
117
117
  let res = await this[type][name].contract.methods[method](...param).call({
@@ -138,7 +138,7 @@ MM_eth.prototype.callList = async function(type, name, method, keys, ...param) {
138
138
  * @param {Function} func event method
139
139
  * @returns {Funtion} this event function key
140
140
  */
141
- MM_eth.prototype.addEvent = function(func, name) {
141
+ Eth.prototype.addEvent = function(func, name) {
142
142
  if (!name) {
143
143
  this.list_count++;
144
144
  name = this.list_count;
@@ -151,7 +151,7 @@ MM_eth.prototype.addEvent = function(func, name) {
151
151
  * Delete event
152
152
  * @param {Function} name event name
153
153
  */
154
- MM_eth.prototype.delEvent = function(name) {
154
+ Eth.prototype.delEvent = function(name) {
155
155
  delete this.list_event[name];
156
156
  };
157
157
 
@@ -159,7 +159,7 @@ MM_eth.prototype.delEvent = function(name) {
159
159
  * execute provider
160
160
  * @param {Object} provider
161
161
  */
162
- MM_eth.prototype.subscribeEvent = function(provider) {
162
+ Eth.prototype.subscribeEvent = function(provider) {
163
163
  if (!provider) {
164
164
  return;
165
165
  }
@@ -221,7 +221,7 @@ MM_eth.prototype.subscribeEvent = function(provider) {
221
221
  * @param {String} address 签名地址
222
222
  * @param {Function} func 回调函数(可选)
223
223
  */
224
- MM_eth.prototype.sign = async function(content, address, func) {
224
+ Eth.prototype.sign = async function(content, address, func) {
225
225
  let ret = null;
226
226
  if (func) {
227
227
  this.web3.eth.sign(content, address, func);
@@ -231,7 +231,7 @@ MM_eth.prototype.sign = async function(content, address, func) {
231
231
  return ret;
232
232
  }
233
233
 
234
- MM_eth.prototype.getBalance = async function(address) {
234
+ Eth.prototype.getBalance = async function(address) {
235
235
  let {
236
236
  chain_accuracy
237
237
  } = this.config;
@@ -259,7 +259,7 @@ MM_eth.prototype.getBalance = async function(address) {
259
259
  * 获取以太网上的账户
260
260
  * @return {Array} 账户数组
261
261
  */
262
- MM_eth.prototype.getAccount = async function() {
262
+ Eth.prototype.getAccount = async function() {
263
263
  this.default_address = this.web3.eth.defaultAccount;
264
264
  return this.default_address;
265
265
  };
@@ -268,7 +268,7 @@ MM_eth.prototype.getAccount = async function() {
268
268
  * 获取以太网上的账户
269
269
  * @return {Array} 账户数组
270
270
  */
271
- MM_eth.prototype.getAccounts = async function() {
271
+ Eth.prototype.getAccounts = async function() {
272
272
  let accounts = await this.web3.eth.getAccounts();
273
273
  if (accounts.length) {
274
274
  this.web3.eth.defaultAccount = accounts[0];
@@ -282,7 +282,7 @@ MM_eth.prototype.getAccounts = async function() {
282
282
  * @param {String} path 地址
283
283
  * @return {String} 加载成功返回true
284
284
  */
285
- MM_eth.prototype.loadAbi = function(abi) {
285
+ Eth.prototype.loadAbi = function(abi) {
286
286
 
287
287
  }
288
288
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_contract",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "这是超级美眉智能合约调用辅助模块,用于快速发布合约和调用区块链ABI方法,适用于eth和tron。",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -45,9 +45,10 @@
45
45
  "homepage": "https://gitee.com/qiuwenwu91/mm_contract#readme",
46
46
  "dependencies": {
47
47
  "bignumber": "^1.1.0",
48
- "web3": "^1.3.0"
48
+ "mm_admin": "^1.2.2",
49
+ "web3": "^4.16.0"
49
50
  },
50
51
  "devDependencies": {
51
- "mm_logs": "^1.0.9"
52
+ "mm_logs": "^1.7.2"
52
53
  }
53
54
  }
File without changes