Skip to content

Commit

Permalink
Updated .eslintrc.js and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
GinMu committed Jan 11, 2019
1 parent 362a416 commit 4938e05
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
env: {
browser: true,
node: true
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
extends: 'eslint:recommended',
'rules': {
'standard/no-callback-literal': [0, ["cb", "callback"]],
'space-before-function-paren': 0,
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ npm install jcc_jingtum_lib

For more information see [docs.md](https://github.com/JCCDex/jcc_jingtum_lib/blob/master/docs.md)

## About Sign

```javascript
// demo
const LocalSign = require('jcc_jingtum_lib/src/local_sign');
let tx = {
Flags: 0,
Fee: 0.00001,
Account: 'jpgWGpfHz8GxqUjz5nb6ej8eZJQtiF6KhH',
TransactionType: 'OfferCreate',
TakerGets: {
value: 0.03,
currency: 'CNY',
issuer: 'jGa9J9TkqtBcUoHe2zqhVFFbgUVED6o9or'
},
TakerPays: 1
}
let seed = {
seed: "snfXQMEVbbZng84CcfdKDASFRi4Hf"
}
let signature = LocalSign(tx, seed);
```

For more structure of transaction data, see [jcc_exchange](https://github.com/JCCDex/jcc_exchange/blob/master/src/tx.js);

## Clone from github

```shell
Expand Down
2 changes: 1 addition & 1 deletion docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ options for setup a remote, options including

bwt是商链的原生币,也是燃料币,商链是井通链的联盟链,如果添加新的联盟链,需要在 [jcc_jingtum_base_lib](https://github.com/JCCDex/jcc_jingtum_base_lib)项目中src/wallet_config.js 添加新的联盟链定义即可,如果需要我们增加请联系我们。

BWT is the native token and gas token of BIZAIN. BIZAIN is the alliance chain of jingtum. If you add a new alliance chain, you need to add a new definition of the alliance chain in project [jcc_jingtum_base_lib](https://github.com/JCCDex/jcc_jingtum_base_lib) folder src/wallet_config.js.
BWT is the native token and gas token of BIZAIN. BIZAIN is the alliance chain of jingtum. If you add a new alliance chain, you need to add a new definition of the alliance chain in project [jcc_jingtum_base_lib](https://github.com/JCCDex/jcc_jingtum_base_lib) folder src/wallet_config.js.

If you need to add it in this package, please contact us.

Expand Down
4 changes: 2 additions & 2 deletions lib/TumAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Amount(token) {
this._currency = null; // new String;
this._issuer = null; // new String;
this._token = token || 'swt'
};
}

var consts = {
currency_xns: 0,
Expand Down Expand Up @@ -67,7 +67,7 @@ Amount.from_json = function (j, token) {

// Only check the value of the Amount
//
Amount.prototype.is_valid = function (j) {
Amount.prototype.is_valid = function () {
// console.log("TODO: decide if the input is a valid amount obj");
return true;
};
Expand Down
21 changes: 7 additions & 14 deletions lib/TypesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ var INVERSE_FIELDS_MAP = {

var SerializedType = function (methods) {
extend(this, methods);
};
}

function isNumber(val) {
return typeof val === 'number' && isFinite(val);
};
}

function isString(val) {
return typeof val === 'string';
};
}

/*
* Use RegExp match function
Expand Down Expand Up @@ -671,9 +671,8 @@ var STHash256 = exports.Hash256 = new SerializedType({
throw new Error('Invalid Hash256');
}
},
parse: function (so) {
parse: function () {
// return UInt256.from_bytes(so.read(32));
console.log("TODO:");
return NaN;
}
});
Expand Down Expand Up @@ -703,9 +702,8 @@ STHash160.id = 17;
var STCurrency = new SerializedType({

// Convert the input JSON format data INTO a BYTE array
from_json_to_bytes: function (j, shouldInterpretSWT) {
from_json_to_bytes: function (j) {
// return (new Currency()).parse_json(j, shouldInterpretSWT);
console.log("Handle input json format currency:", j, typeof (j));

var val = new Array(20); // return byte array representing currency code
for (var i = 0; i < 20; i++) {
Expand Down Expand Up @@ -741,22 +739,20 @@ var STCurrency = new SerializedType({
break;
case 'number':
// TODO, follow the Tum code rules
console.log("Nmber");
throw new Error("Input tum code not valid!");
// if (!isNaN(j)) {
// this.parse_number(j);
// }
// break;
case 'object':
console.log("Object");
throw new Error("Input tum code not valid!");
// break;
}

return val;
},

serialize: function (so, val, swt_as_ascii) {
serialize: function (so, val) {
var currencyData = val.to_bytes();
if (!currencyData) {
throw new Error('Tried to serialize invalid/unimplemented currency type.');
Expand Down Expand Up @@ -1336,7 +1332,6 @@ function get_transaction_type(structure) {
throw new Error('Invalid input type for transaction type!');
} // end typeof structure

console.log('Get tx type:', output);
return output;
}

Expand Down Expand Up @@ -1454,9 +1449,8 @@ function get_transaction_result(structure) {
throw new Error('Invalid input type for transaction result!');
} // end typeof structure

console.log('Get tx result:', output);
return output;
};
}

exports.get_transaction_result = get_transaction_result;

Expand Down Expand Up @@ -1558,7 +1552,6 @@ function get_ledger_entry_type(structure) {
output = 'UndefinedLedgerEntry';
} // end typeof structure

console.log('Get ledger entry type:', output);
return output;
}

Expand Down
10 changes: 6 additions & 4 deletions src/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Remote(options) {
maxAge: 1000 * 60 * 5
}); // 2100 size, 5 min

self.on('newListener', function (type, listener) {
self.on('newListener', function (type) {
if (!self._server.isConnected()) return;
if (type === 'removeListener') return;
if (type === 'transactions') {
Expand Down Expand Up @@ -111,7 +111,9 @@ Remote.prototype._handleMessage = function (e) {
var data;
try {
data = JSON.parse(e.data);
} catch (e) {}
} catch (e) {
data = "";
}
if (typeof data !== 'object') return;
switch (data.type) {
case 'ledgerClosed':
Expand Down Expand Up @@ -408,7 +410,7 @@ function getRelationType(type) {
* @returns {Request}
* @private
*/
Remote.prototype.__requestAccount = function (type, options, request, filter) {
Remote.prototype.__requestAccount = function (type, options, request) {
// var request = new Request(this, type, filter);
request._command = type;
var self = this
Expand Down Expand Up @@ -1127,7 +1129,7 @@ Remote.prototype.__buildDelegateKeySet = function (options, tx) {
return tx;
};

Remote.prototype.__buildSignerSet = function (options, tx) {
Remote.prototype.__buildSignerSet = function () {
// TODO
return null;
};
Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Server.prototype._handleClose = function () {
if (self._timer !== 0) return;
self._remote.emit('disconnect');
self._timer = setInterval(function () {
self.connect(function (err, ret) {
self.connect(function (err) {
if (!err) {
clearInterval(self._timer);
self._timer = 0;
Expand Down
16 changes: 6 additions & 10 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Event = require('events').EventEmitter;
var utf8 = require('utf8');
var utils = require('./utils');
var Wallet = require('jcc_jingtum_base_lib').Wallet;
var jser = require('../lib/Serializer').Serializer;
var sign = require('./local_sign');
/**
* Post request to server with account secret
* @param remote
Expand Down Expand Up @@ -295,12 +295,10 @@ function signing(self, callback) {
self.tx_json.TakerGets = Number(self.tx_json.TakerGets) / 1000000;
}
try {
var wt = new Wallet(self._secret, self._token);
self.tx_json.SigningPubKey = wt.getPublicKey();
var prefix = 0x53545800;
var hash = jser.from_json(self.tx_json, self._token).hash(prefix, self._token);
self.tx_json.TxnSignature = wt.signTx(hash);
self.tx_json.blob = jser.from_json(self.tx_json, self._token).to_hex();
var seed = {
seed: self._secret
}
self.tx_json.blob = sign(self.tx_json, seed, self._token);
self._local_sign = true;
callback(null, self.tx_json.blob);
} catch (e) {
Expand All @@ -312,7 +310,6 @@ Transaction.prototype.sign = function (callback) {
var self = this;
if (self.tx_json.Sequence) {
signing(self, callback);
// callback(null, signing(self));
} else {
var req = this._remote.requestAccountInfo({
account: self.tx_json.Account,
Expand All @@ -322,7 +319,6 @@ Transaction.prototype.sign = function (callback) {
if (err) return callback(err);
self.tx_json.Sequence = data.account_data.Sequence;
signing(self, callback);
// callback(null, signing(self));
});
}
};
Expand All @@ -346,7 +342,7 @@ Transaction.prototype.submit = function (callback) {
};
self._remote._submit('submit', data, self._filter, callback);
} else if (self._remote._local_sign) { // 签名之后传给底层
self.sign(function (err, blob) {
self.sign(function (err) {
if (err) {
return callback('sign error: ' + err);
} else {
Expand Down

0 comments on commit 4938e05

Please sign in to comment.