Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var HttpProvider = require('web3-providers-http');
var Chain3 = require('../packages/chain3')
var utils = require('../packages/chain3-utils')

var httpProvider = new HttpProvider('http://localhost:8545');
var chain3 = new Chain3(httpProvider);

chain3.mc.net.getNetworkType().then(function(res){
console.log('network type:'+res); //res.result);
},function(err){
console.log('get NetworkType,'+err);
});


chain3.mc.getAccounts().then(function(results){
console.log("Total accounts :", results.length);
results.forEach(function(res,index){
console.log('account['+index+'] :'+res);
});
},function(err){
console.log('getAccount,'+err);
});

chain3.mc.getAccounts().then(function(results){
return chain3.mc.getBalance(results[0]);
}).then(function(balance){
console.log('balance:'+balance.toString(10));
console.log(utils.fromSha(balance.toString(),'mc')+ ' mc');
console.log(utils.fromSha(balance.toString(),'Gsha'), 'Gsha');
},function(err){
console.log('getBalance,'+err);
});

arg = {
from: '0xEc27B756BCBFd129C392AbEb4195069560710DD0', // checksum address
to: '0xeef152b480a0c8eaeeeea9e0a711a8de09526f51', // checksum address
value: '1234567654321',
gasPrice: '324234234234'
};
chain3.mc.sendTransaction(arg).then(function(result){
console.log('send tx success,tx hash:'+result.transactionHash);
},function(err){
console.log('send tx ,'+err);
});






41 changes: 41 additions & 0 deletions packages/chain3-scs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# chain3-scs

This is a sub package of [chain3.js][repo]

This is the Eth package to be used [chain3.js][repo].
Please read the [documentation][docs] for more.

## Installation

### Node.js

```bash
npm install chain3-scs
```

### In the Browser

Build running the following in the [web3.js][repo] repository:

```bash
npm run-script build-all
```

Then include `dist/chain3-mc.js` in your html file.
This will expose the `Chain3Mc` object on the window object.


## Usage

```js
// in node.js
var Chain3Scs = require('chain3-scs');

var mc = new Chain3Scs('ws://localhost:8546');
```


[docs]: http://web3js.readthedocs.io/en/1.0/
[repo]: https://github.com/ethereum/web3.js


229 changes: 229 additions & 0 deletions packages/chain3-scs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
This file is part of chain3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file index.js
* @author Fabian Vogelsteller <fabian@ethereum.org>
* @date 2017
* Update with chain3 packages
* chain3-mc-accounts
*/

"use strict";

var _ = require('underscore');
var core = require('web3-core');
var helpers = require('web3-core-helpers');
var Subscriptions = require('web3-core-subscriptions').subscriptions;
var Method = require('../../chain3-core-method');
var utils = require('web3-utils');


var BaseContract = require('../../chain3-mc-contract');
var abi = require('web3-eth-abi');

var formatter = helpers.formatters;



var Scs = function Scs() {
var _this = this;

core.packageInit(this, arguments);

// overwrite setProvider
var setProvider = this.setProvider;
this.setProvider = function () {
setProvider.apply(_this, arguments);
_this.net.setProvider.apply(_this, arguments);
_this.personal.setProvider.apply(_this, arguments);
_this.accounts.setProvider.apply(_this, arguments);
_this.Contract.setProvider(_this.currentProvider, _this.accounts);
};


var hive = null;
var info = null;

Object.defineProperty(this, 'hive', {
get: function () {
return hive;
},
set: function (val) {
if(val) {
hive = utils.toChecksumAddress(formatter.inputAddressFormatter(val));
}


return val;
},
enumerable: true
});
Object.defineProperty(this, 'info', {
get: function () {
return info;
},
set: function (info) {
info = val;


return val;
},
enumerable: true
});


this.clearSubscriptions = _this._requestManager.clearSubscriptions;



var self = this;


var methods = [
new Method({
name: 'directCall',
call: 'scs_directCall',
params: 1,
inputFormatter: [formatter.inputCallFormatter]
}),
new Method({
name: 'getBlock',
call: 'scs_getBlock',
params: 2,
inputFormatter: [formatter.inputAddressFormatter,formatter.inputDefaultBlockNumberFormatter]
}),
new Method({
name: 'getBlockList',
call: 'scs_getBlockList',
params: 3,
inputFormatter: [formatter.inputAddressFormatter,utils.numberToHex,utils.numberToHex]
}),
new Method({
name: 'getDappState',
call: 'scs_getDappState',
params: 1,
inputFormatter: [formatter.inputAddressFormatter],
outputFormatter: utils.hexToNumber
}),
new Method({
name: 'getMicroChainList',
call: 'scs_getMicroChainList',
params: 0
}),
new Method({
name: 'getSCSId',
call: 'scs_getSCSId',
params: 0
}),
new Method({
name: 'getReceiptByHash',
call: 'scs_getReceiptByHash',
params: 2,
inputFormatter: [formatter.inputAddressFormatter,null]
}),
new Method({
name: 'getReceiptByNonce',
call: 'scs_getReceiptByNonce',
params: 3,
inputFormatter: [formatter.inputAddressFormatter,null,null]
}),
new Method({
name: 'getTransactionByHash',
call: 'scs_getTransactionByHash',
params: 2,
inputFormatter: [formatter.inputAddressFormatter,null]
}),
new Method({
name: 'getTransactionByNonce',
call: 'scs_getTransactionByNonce',
params: 3,
inputFormatter: [formatter.inputAddressFormatter,null, null]
}),
new Method({
name: 'getExchangeByAddress',
call: 'scs_getExchangeByAddress',
params: 10,
inputFormatter: [formatter.inputAddressFormatter,
formatter.inputAddressFormatter,utils.hexToNumber,
utils.hexToNumber, utils.hexToNumber,
utils.hexToNumber,utils.hexToNumber,
utils.hexToNumber,utils.hexToNumber,
utils.hexToNumber,utils.hexToNumber,
utils.hexToNumber]
}),
new Method({
name: 'getExchangeInfo',
call: 'scs_getExchangeInfo',
params: 10,
inputFormatter: [formatter.inputAddressFormatter,
formatter.inputAddressFormatter,utils.hexToNumber,
utils.hexToNumber, utils.hexToNumber,
utils.hexToNumber,utils.hexToNumber,
utils.hexToNumber,utils.hexToNumber,
utils.hexToNumber,utils.hexToNumber,
utils.hexToNumber]
}),
new Method({
name: 'getTxpool',
call: 'scs_getTxpool',
params: 1,
inputFormatter: [formatter.inputAddressFormatter]
}),
new Method({
name: 'getMicroChainInfo',
call: 'scs_getMicroChainInfo',
params: 1,
inputFormatter: [formatter.inputAddressFormatter]
}),
new Method({
name: 'getBalance',
call: 'scs_getBalance',
params: 2,
inputFormatter: [formatter.inputAddressFormatter,formatter.inputAddressFormatter]
}),
new Method({
name: 'getBlockNumber',
call: 'scs_getBlockNumber',
params: 1,
inputFormatter: [formatter.inputAddressFormatter]
}),
new Method({
name: 'getNonce',
call: 'scs_getNonce',
params: 2,
inputFormatter: [formatter.inputAddressFormatter,formatter.inputAddressFormatter]
})

];



methods.forEach(function(method) {
method.attachToObject(_this);
method.setRequestManager(_this._requestManager, _this.accounts); // second param means is eth.accounts (necessary for wallet signing)
//console.log('mc, foreach after set manager');
method.defaultBlock = _this.defaultBlock;
method.defaultAccount = _this.defaultAccount;
});

};

core.addProviders(Scs);


module.exports = Scs;

21 changes: 21 additions & 0 deletions packages/chain3-scs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "chain3-scs",
"version": "1.0.0",
"description": "chain3 module to interact with the MOAC blockchain and smart contracts.",
"repository": "https://github.com/MOACChain/chain3/tree/1.x/packages/chain3-scs",
"license": "LGPL-3.0",
"engines": {
"node": ">=8.0.0"
},
"main": "src/index.js",
"dependencies": {
"underscore": "1.9.1",
"web3-core": "1.2.1",
"web3-core-helpers": "1.2.1",
"web3-core-subscriptions": "1.2.1",
"web3-eth-abi": "1.2.1",
"web3-eth-iban": "1.2.1",
"web3-eth-personal": "1.2.1",
"web3-net": "1.2.1"
}
}
2 changes: 1 addition & 1 deletion test/mc.sendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,4 @@ describe(method, function () {
}
});
});
});
});