aelf-sdk-lys1988
Version:
aelf-sdk js library
2,025 lines (1,878 loc) • 1.73 MB
JavaScript
require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
/*!
* web3.js - Ethereum JavaScript API
*
* @license lgpl-3.0
* @see https://github.com/ethereum/web3.js
*/
/*
* This file is part of web3.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 web3.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* Gav Wood <g@ethdev.com>
* @date 2014
*/
var RequestManager = require('./aelf/requestmanager');
var Chain = require('./aelf/methods/chain');
var Settings = require('./aelf/settings');
var version = require('./version.json');
var HttpProvider = require('./aelf/httpprovider');
var wallet = require('./aelf/wallet');
function Aelf (provider) {
this._requestManager = new RequestManager(provider);
this.currentProvider = provider;
this.chain = new Chain(this);
this.settings = new Settings();
this.version = {
api: version.version
};
this.providers = {
HttpProvider: HttpProvider
};
}
// expose providers on the class
Aelf.providers = {
HttpProvider: HttpProvider
};
Aelf.prototype.setProvider = function (provider) {
this._requestManager.setProvider(provider);
this.currentProvider = provider;
};
Aelf.prototype.reset = function (keepIsSyncing) {
this._requestManager.reset(keepIsSyncing);
this.settings = new Settings();
};
Aelf.prototype.isConnected = function(){
return (this.currentProvider && this.currentProvider.isConnected());
};
Aelf.prototype.wallet = wallet;
Aelf.wallet = wallet;
if (typeof window !== 'undefined' && !window.Aelf) {
window.Aelf = Aelf;
}
module.exports = Aelf;
},{"./aelf/httpprovider":4,"./aelf/methods/chain":7,"./aelf/requestmanager":13,"./aelf/settings":14,"./aelf/wallet":34,"./version.json":38}],2:[function(require,module,exports){
/*
This file is part of web3.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 errors.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
module.exports = {
InvalidNumberOfRPCParams: function () {
return new Error('Invalid number of input parameters to RPC method');
},
InvalidConnection: function (host){
return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.');
},
InvalidProvider: function () {
return new Error('Provider not set or invalid');
},
InvalidResponse: function (result){
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result);
return new Error(message);
},
ConnectionTimeout: function (ms){
return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
}
};
},{}],3:[function(require,module,exports){
(function (Buffer){
/*
This file is part of web3.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 formatters.js
* @author Marek Kotewicz <marek@ethdev.com>
* @author Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
'use strict';
var protobuf = require('protobufjs');
var abiDescriptor = require('./proto/abi.proto.json')
var ModuleMessage = protobuf.Root.fromJSON(abiDescriptor).Module;
var authDescriptor = require('./proto/auth.proto.json')
var proposalMessage = protobuf.Root.fromJSON(authDescriptor).Proposal;
var inputAddressFormatter = function (address) {
// if (address.startsWith('ELF_')) {
// var parts = address.split('_');
// var b58rep = parts[parts.length - 1];
// return base58check.decode(b58rep, 'hex');
// }
// throw new Error('invalid address');
return address;
};
var outputAbiFormatter = function (result) {
// var root = protobuf.Root.fromJSON(abiDescriptor);
// var ModuleMessage = root.Module;
var buffer = Buffer.from(result.abi.replace('0x', ''), 'hex');
result.abi = ModuleMessage.decode(buffer);
return result.abi;
};
module.exports = {
inputAddressFormatter: inputAddressFormatter,
outputAbiFormatter: outputAbiFormatter
};
}).call(this,require("buffer").Buffer)
},{"./proto/abi.proto.json":9,"./proto/auth.proto.json":10,"buffer":93,"protobufjs":192}],4:[function(require,module,exports){
(function (Buffer){
/*
This file is part of web3.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 httpprovider.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
var errors = require('./errors');
// workaround to use httpprovider in different envs
// browser
if (typeof window !== 'undefined' && window.XMLHttpRequest) {
XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
// node
} else {
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
}
var XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line
/**
* HttpProvider should be used to send rpc calls over http
*/
var HttpProvider = function (host, timeout, user, password, headers) {
this.host = host || 'http://localhost:8545';
this.timeout = timeout || 0;
this.user = user;
this.password = password;
this.headers = headers;
};
/**
* Should be called to prepare new XMLHttpRequest
*
* @method prepareRequest
* @param {Boolean} true if request should be async
* @return {XMLHttpRequest} object
*/
HttpProvider.prototype.prepareRequest = function (async) {
var request;
if (async) {
request = new XHR2();
request.timeout = this.timeout;
} else {
request = new XMLHttpRequest();
}
request.withCredentials = false;
request.open('POST', this.host, async);
if (this.user && this.password) {
var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64');
request.setRequestHeader('Authorization', auth);
}
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', 'application/json', true);
if(this.headers) {
this.headers.forEach(function(header) {
request.setRequestHeader(header.name, header.value);
});
}
return request;
};
/**
* Should be called to make sync request
*
* @method send
* @param {Object} payload
* @return {Object} result
*/
HttpProvider.prototype.send = function (payload) {
var request = this.prepareRequest(false);
try {
request.send(JSON.stringify(payload));
} catch (error) {
throw errors.InvalidConnection(this.host);
}
var result = request.responseText;
try {
result = JSON.parse(result);
} catch (e) {
throw errors.InvalidResponse(request.responseText);
}
return result;
};
/**
* Should be used to make async request
*
* @method sendAsync
* @param {Object} payload
* @param {Function} callback triggered on end with (err, result)
*/
HttpProvider.prototype.sendAsync = function (payload, callback) {
var request = this.prepareRequest(true);
request.onreadystatechange = function () {
if (request.readyState === 4 && request.timeout !== 1) {
var result = request.responseText;
var error = null;
try {
result = JSON.parse(result);
} catch (e) {
error = errors.InvalidResponse(request.responseText);
}
callback(error, result);
}
};
request.ontimeout = function () {
callback(errors.ConnectionTimeout(this.timeout));
};
try {
request.send(JSON.stringify(payload));
} catch (error) {
callback(errors.InvalidConnection(this.host));
}
};
/**
* Synchronously tries to make Http request
*
* @method isConnected
* @return {Boolean} returns true if request haven't failed. Otherwise false
*/
HttpProvider.prototype.isConnected = function () {
try {
this.send({
id: 9999,
jsonrpc: '2.0',
method: 'connect_chain',
params: {}
});
return true;
} catch (e) {
return false;
}
};
module.exports = HttpProvider;
}).call(this,require("buffer").Buffer)
},{"./errors":2,"buffer":93,"xhr2-cookies":277,"xmlhttprequest":282}],5:[function(require,module,exports){
/*
This file is part of web3.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 jsonrpc.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Aaron Kumavis <aaron@kumavis.me>
* @date 2015
*/
// Initialize Jsonrpc as a simple object with utility functions.
var Jsonrpc = {
messageId: 0
};
/**
* Should be called to valid json create payload object
*
* @method toPayload
* @param {Function} method of jsonrpc call, required
* @param {Array} params, an array of method params, optional
* @returns {Object} valid jsonrpc payload object
*/
Jsonrpc.toPayload = function (method, params) {
if (!method)
console.error('jsonrpc method should be specified!');
// advance message ID
Jsonrpc.messageId++;
return {
jsonrpc: '2.0',
id: Jsonrpc.messageId,
method: method,
params: params || {}
};
};
/**
* Should be called to check if jsonrpc response is valid
*
* @method isValidResponse
* @param {Object}
* @returns {Boolean} true if response is valid, otherwise false
*/
Jsonrpc.isValidResponse = function (response) {
return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response);
function validateSingleMessage(message){
return !!message &&
!message.error &&
message.jsonrpc === '2.0' &&
typeof message.id === 'number' &&
message.result !== undefined; // only undefined is not valid json object
}
};
/**
* Should be called to create batch payload object
*
* @method toBatchPayload
* @param {Array} messages, an array of objects with method (required) and params (optional) fields
* @returns {Array} batch payload
*/
Jsonrpc.toBatchPayload = function (messages) {
return messages.map(function (message) {
return Jsonrpc.toPayload(message.method, message.params);
});
};
module.exports = Jsonrpc;
},{}],6:[function(require,module,exports){
/*
This file is part of web3.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 method.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
var utils = require('../utils/utils');
var errors = require('./errors');
var Method = function (options) {
this.name = options.name;
this.call = options.call;
this.params = options.params || [];
this.inputFormatter = options.inputFormatter;
this.outputFormatter = options.outputFormatter;
this.requestManager = null;
};
Method.prototype.setRequestManager = function (rm) {
this.requestManager = rm;
};
/**
* Should be used to determine name of the jsonrpc method based on arguments
*
* @method getCall
* @param {Array} arguments
* @return {String} name of jsonrpc method
*/
Method.prototype.getCall = function (args) {
return utils.isFunction(this.call) ? this.call(args) : this.call;
};
/**
* Should be used to extract callback from array of arguments. Modifies input param
*
* @method extractCallback
* @param {Array} arguments
* @return {Function|Null} callback, if exists
*/
Method.prototype.extractCallback = function (args) {
if (utils.isFunction(args[args.length - 1])) {
return args.pop(); // modify the args array!
}
};
/**
* Should be called to check if the number of arguments is correct
*
* @method validateArgs
* @param {Array} arguments
* @throws {Error} if it is not
*/
Method.prototype.validateArgs = function (args) {
if (args.length !== this.params.length) {
throw errors.InvalidNumberOfRPCParams();
}
};
/**
* Should be called to format input args of method
*
* @method formatInput
* @param {Array}
* @return {Array}
*/
Method.prototype.formatInput = function (args) {
if (!this.inputFormatter) {
return args;
}
return this.inputFormatter.map(function (formatter, index) {
return formatter ? formatter(args[index]) : args[index];
});
};
/**
* Should be called to format output(result) of method
*
* @method formatOutput
* @param {Object}
* @return {Object}
*/
Method.prototype.formatOutput = function (result) {
return this.outputFormatter && result ? this.outputFormatter(result) : result;
};
/**
* Should create payload from given input args
*
* @method toPayload
* @param {Array} args
* @return {Object}
*/
Method.prototype.toPayload = function (args) {
var call = this.getCall(args);
var callback = this.extractCallback(args);
var params = this.formatInput(args);
this.validateArgs(params);
var objparams = new Object();
for(var i =0; i< params.length; i++){
objparams[this.params[i]] = params[i];
}
return {
method: call,
params: objparams,
callback: callback
};
};
Method.prototype.attachToObject = function (obj) {
var func = this.buildCall();
func.call = this.call; // TODO!!! that's ugly. filter.js uses it
var name = this.name.split('.');
if (name.length > 1) {
obj[name[0]] = obj[name[0]] || {};
obj[name[0]][name[1]] = func;
} else {
obj[name[0]] = func;
}
};
Method.prototype.buildCall = function() {
var method = this;
var send = function () {
var payload = method.toPayload(Array.prototype.slice.call(arguments));
if (payload.callback) {
return method.requestManager.sendAsync(payload, function (err, result) {
payload.callback(err, method.formatOutput(result));
});
}
return method.formatOutput(method.requestManager.send(payload));
};
send.request = this.request.bind(this);
return send;
};
/**
* Should be called to create pure JSONRPC request which can be used in batch request
*
* @method request
* @param {...} params
* @return {Object} jsonrpc request
*/
Method.prototype.request = function () {
var payload = this.toPayload(Array.prototype.slice.call(arguments));
payload.format = this.formatOutput.bind(this);
return payload;
};
module.exports = Method;
},{"../utils/utils":37,"./errors":2}],7:[function(require,module,exports){
/*
This file is part of web3.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 eth.js
* @author Marek Kotewicz <marek@ethdev.com>
* @author Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
"use strict";
var formatters = require('../formatters');
var Contract = require('../shims/contract.js');
var Method = require('../method');
var c = require('../../utils/config');
// var blockCall = function (args) {
// return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
// };
// var transactionFromBlockCall = function (args) {
// return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
// };
// var uncleCall = function (args) {
// return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
// };
// var getBlockTransactionCountCall = function (args) {
// return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
// };
// var uncleCountCall = function (args) {
// return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
// };
function Chain(aelf) {
this._requestManager = aelf._requestManager;
this._initialized = false;
var self = this;
methods().forEach(function(method) {
method.attachToObject(self);
method.setRequestManager(self._requestManager);
});
properties().forEach(function(p) {
p.attachToObject(self);
p.setRequestManager(self._requestManager);
});
}
Object.defineProperty(Chain.prototype, 'chainId', {
get: function () {
return c.chainId;
},
set: function (val) {
c.chainId = val;
return val;
}
});
Object.defineProperty(Chain.prototype, 'contractZeroAddress', {
get: function () {
return c.contractZeroAddress;
},
set: function (val) {
c.contractZeroAddress = val;
return val;
}
});
Object.defineProperty(Chain.prototype, 'contractZeroAbi', {
get: function () {
return c.contractZeroAbi;
},
set: function (val) {
c.contractZeroAbi = val;
return val;
}
});
Object.defineProperty(Chain.prototype, 'contractZero', {
get: function () {
return c.contractZero;
},
set: function (val) {
c.contractZero = val;
return val;
}
});
Object.defineProperty(Chain.prototype, 'defaultAccount', {
get: function () {
return c.defaultAccount;
},
set: function (val) {
c.defaultAccount = val;
return val;
}
});
var methods = function () {
var getCommands = new Method({
name: 'getCommands',
call: 'get_commands',
params: [],
});
var connectChain = new Method({
name: 'connectChain',
call: 'connect_chain',
params: [],
});
var getContractAbi = new Method({
name: 'getContractAbi',
call: 'get_contract_abi',
params: ['address'],
inputFormatter: [formatters.inputAddressFormatter],
outputFormatter: formatters.outputAbiFormatter
});
var getBlockHeight = new Method({
name: 'getBlockHeight',
call: 'get_block_height',
params: [],
inputFormatter: []
});
var getBlockInfo = new Method({
name: 'getBlockInfo',
call: 'get_block_info',
params: ['block_height', 'include_txs']
});
var getIncrement = new Method({
name: 'getIncrement',
call: 'get_increment',
params: ['address'],
inputFormatter: [formatters.inputAddressFormatter]
});
var getTxResult = new Method({
name: 'getTxResult',
call: 'get_tx_result',
params: ['txhash'],
inputFormatter: [null]
});
var getTxsResultByBlockhash = new Method({
name: 'getTxsResult',
call: 'get_txs_result',
params: ['blockhash', 'offset', 'num']
});
var getMerklePath = new Method({
name: 'getMerklePath',
call: 'get_merkle_path',
params: ['txid'],
inputFormatter: [null]
});
var sendTransaction = new Method({
name: 'sendTransaction',
call: 'broadcast_tx',
params: ['rawtx'],
inputFormatter: [null]
});
var checkProposal = new Method({
name: 'checkProposal',
call: 'check_proposal',
params: ['proposal_id'],
inputFormatter: [null]
});
var callReadOnly = new Method({
name: 'callReadOnly',
call: 'call',
params: ['rawtx'],
inputFormatter: [null]
});
return [
getCommands,
connectChain,
getContractAbi,
getBlockHeight,
getBlockInfo,
getIncrement,
sendTransaction,
callReadOnly,
getTxResult,
getTxsResultByBlockhash,
getMerklePath,
checkProposal
];
};
var properties = function () {
// TODO: implement
return [
// new Property({
// name: 'coinbase',
// getter: 'eth_coinbase'
// })
];
};
Chain.prototype.contract = function (abi, wallet) {
var factory = new Contract(this, abi, wallet);
return factory;
};
Chain.prototype.contractAt = function (address, wallet) {
var abi = this.getContractAbi(address);
var factory = new Contract(this, abi, wallet);
return factory.at(address);
};
Chain.prototype.initChainInfo = function(){
if(this._initialized){
return;
}
var chainInfo = this.connectChain().result;
this.chainId = chainInfo.chain_id;
this.contractZeroAddress = chainInfo.genesis_contract;
this.contractZeroAbi = this.getContractAbi(this.contractZeroAddress);
this.contractZero = this.contract(this.contractZeroAbi).at(this.contractZeroAddress);
this._initialized = true;
};
module.exports = Chain;
},{"../../utils/config":36,"../formatters":3,"../method":6,"../shims/contract.js":15}],8:[function(require,module,exports){
(function (Buffer){
'use strict';
var utils = require('../utils/utils');
var protobuf = require('protobufjs');
var kernelDescriptor = require('./proto/kernel.proto.json');
var kernelRoot = protobuf.Root.fromJSON(kernelDescriptor);
var authDescriptor = require('./proto/auth.proto.json');
var auth = protobuf.Root.fromJSON(authDescriptor);
var crossChainDescriptor = require('./proto/crosschain.proto.json');
var crosschain = protobuf.Root.fromJSON(crossChainDescriptor);
var getAddressFromRep = function(rep){
var hex = utils.decodeAddressRep(rep);
return kernelRoot.Address.create({'Value': Buffer.from(hex.replace('0x', ''), 'hex')});
};
var getHashFromHex = function(hex){
return kernelRoot.Hash.create({'Value': Buffer.from(hex.replace('0x', ''), 'hex')});
};
var encodeTransaction = function(tx){
return kernelRoot.Transaction.encode(tx).finish();
};
var getTransaction = function(from, to, methodName, params){
var txn = {
"From": getAddressFromRep(from),
"To": getAddressFromRep(to),
"MethodName": methodName,
"Params": params
};
return kernelRoot.Transaction.create(txn);
};
var getMsigTransaction = function(from, to, methodName, params){
var txn = {
"From": getAddressFromRep(from),
"To": getAddressFromRep(to),
"MethodName": methodName,
"Params": params,
"Type" : kernelRoot.TransactionType.MsigTransaction
};
return kernelRoot.Transaction.create(txn);
};
var getReviewer = function(reviewer){
var value = {
'PubKey': Buffer.from(reviewer.PubKey.replace('0x', ''), 'hex'),
'Weight': reviewer.Weight
};
return auth.Reviewer.create(value);
};
var getAuthorization = function (decided_threshold, proposer_threshold, reviewers) {
var authorization = {
"ExecutionThreshold" : decided_threshold,
"ProposerThreshold" : proposer_threshold,
"Reviewers" : reviewers
};
return auth.Authorization.create(authorization);
};
var getProposal = function (multisig_account, proposal_name, raw_txn, expired_time, proposer) {
var txn_data = encodeTransaction(raw_txn);
var proposal = {
"MultiSigAccount" : getAddressFromRep(multisig_account),
"Name" : proposal_name,
"TxnData" : txn_data,
"ExpiredTime" : (new Date(expired_time).getTime())/ 1000,
"Status" : auth.ProposalStatus.ToBeDecided,
"Proposer" : getAddressFromRep(proposer)
};
return auth.Proposal.create(proposal);
};
var getApproval =function (proposalHash, signature) {
var approval = {
'ProposalHash' : getHashFromHex(proposalHash),
'Signature' : signature
};
return auth.Approval.create(approval);
};
var getSideChainInfo = function (locked_token_amount, indexing_price, pairs, code, proposer) {
var sideChainInfo ={
'IndexingPrice': indexing_price,
'LockedTokenAmount': locked_token_amount,
'ResourceBalances': pairs,
'ContractCode': code,
'Proposer': getAddressFromRep(proposer),
'SideChainStatus': crosschain.SideChainStatus.Apply
};
return crosschain.SideChainInfo.create(sideChainInfo);
};
var getBalance = function (resource_balance) {
var pair = {
'Type' : resource_balance.Type,
'Amount' : resource_balance.Amount
};
return crosschain.ResourceTypeBalancePair.create(pair);
};
var encodeProposal =function (proposal, fieldNumber) {
var value = auth.Proposal.encode(proposal).finish();
var w = new protobuf.BufferWriter();
// Tag
w.uint32(fieldNumber << 3 | 2);
// Data
w.bytes(value);
return w.finish();
};
var encodeSideChainInfo =function (sideChainInfo, fieldNumber) {
var value = crosschain.SideChainInfo.encode(sideChainInfo).finish();
var w = new protobuf.BufferWriter();
// Tag
w.uint32(fieldNumber << 3 | 2);
// Data
w.bytes(value);
return w.finish();
};
var encodeApproval = function (approval, fieldNumber) {
var value = auth.Approval.encode(approval).finish();
var w = new protobuf.BufferWriter();
// Tag
w.uint32(fieldNumber << 3 | 2);
// Data
w.bytes(value);
return w.finish();
};
module.exports = {
getAddressFromRep: getAddressFromRep,
getHashFromHex: getHashFromHex,
getTransaction: getTransaction,
getMsigTransaction: getMsigTransaction,
getAuthorization: getAuthorization,
getReviewer: getReviewer,
encodeTransaction: encodeTransaction,
getProposal: getProposal,
encodeProposal : encodeProposal,
getApproval: getApproval,
encodeApproval:encodeApproval,
getSideChainInfo: getSideChainInfo,
getBalance: getBalance,
encodeSideChainInfo: encodeSideChainInfo,
Transaction: kernelRoot.Transaction,
Hash: kernelRoot.Hash,
Address: kernelRoot.Address,
Authorization: auth.Authorization,
Proposal: auth.Proposal,
ProposalStatus: auth.ProposalStatus,
SideChainInfo: crosschain.SideChainInfo,
SideChainStatus: crosschain.SideChainStatus,
ResourceTypeBalancePair: crosschain.ResourceTypeBalancePair
};
}).call(this,require("buffer").Buffer)
},{"../utils/utils":37,"./proto/auth.proto.json":10,"./proto/crosschain.proto.json":11,"./proto/kernel.proto.json":12,"buffer":93,"protobufjs":192}],9:[function(require,module,exports){
module.exports={
"options": {
"csharp_namespace": "AElf.ABI.CSharp"
},
"nested": {
"Field": {
"fields": {
"Type": {
"type": "string",
"id": 1
},
"Name": {
"type": "string",
"id": 2
}
}
},
"Type": {
"fields": {
"Name": {
"type": "string",
"id": 1
},
"Fields": {
"rule": "repeated",
"type": "Field",
"id": 2
}
}
},
"Event": {
"fields": {
"Name": {
"type": "string",
"id": 1
},
"Indexed": {
"rule": "repeated",
"type": "Field",
"id": 2
},
"NonIndexed": {
"rule": "repeated",
"type": "Field",
"id": 3
}
}
},
"Method": {
"fields": {
"Name": {
"type": "string",
"id": 1
},
"Params": {
"rule": "repeated",
"type": "Field",
"id": 2
},
"ReturnType": {
"type": "string",
"id": 3
},
"IsView": {
"type": "bool",
"id": 4
},
"IsAsync": {
"type": "bool",
"id": 5
}
}
},
"Module": {
"fields": {
"Name": {
"type": "string",
"id": 1
},
"Methods": {
"rule": "repeated",
"type": "Method",
"id": 2
},
"Events": {
"rule": "repeated",
"type": "Event",
"id": 3
},
"Types": {
"rule": "repeated",
"type": "Type",
"id": 4
}
}
}
}
}
},{}],10:[function(require,module,exports){
module.exports={
"options": {
"csharp_namespace": "AElf.Kernel"
},
"nested": {
"Authorization": {
"fields": {
"MultiSigAccount": {
"type": "Address",
"id": 1
},
"ExecutionThreshold": {
"type": "uint32",
"id": 2
},
"ProposerThreshold": {
"type": "uint32",
"id": 3
},
"Reviewers": {
"rule": "repeated",
"type": "Reviewer",
"id": 4
}
}
},
"Reviewer": {
"fields": {
"PubKey": {
"type": "bytes",
"id": 1
},
"Weight": {
"type": "uint32",
"id": 2
}
}
},
"Proposal": {
"fields": {
"MultiSigAccount": {
"type": "Address",
"id": 1
},
"Name": {
"type": "string",
"id": 2
},
"TxnData": {
"type": "bytes",
"id": 3
},
"ExpiredTime": {
"type": "double",
"id": 4
},
"Status": {
"type": "ProposalStatus",
"id": 5
},
"Proposer": {
"type": "Address",
"id": 6
}
}
},
"ProposalStatus": {
"values": {
"ToBeDecided": 0,
"Decided": 1,
"Released": 2
}
},
"Approved": {
"fields": {
"ProposalHash": {
"type": "Hash",
"id": 1
},
"Approvals": {
"rule": "repeated",
"type": "Approval",
"id": 5
}
}
},
"Approval": {
"fields": {
"ProposalHash": {
"type": "Hash",
"id": 1
},
"Signature": {
"type": "bytes",
"id": 2
}
}
},
"google": {
"nested": {
"protobuf": {
"nested": {
"Timestamp": {
"fields": {
"seconds": {
"type": "int64",
"id": 1
},
"nanos": {
"type": "int32",
"id": 2
}
}
}
}
}
}
},
"Address": {
"fields": {
"Value": {
"type": "bytes",
"id": 1
}
}
},
"Hash": {
"fields": {
"Value": {
"type": "bytes",
"id": 1
},
"HashType": {
"type": "HashType",
"id": 2
}
}
},
"HashType": {
"values": {
"General": 0,
"AccountAddress": 1,
"ResourcePath": 2,
"ResourcePointer": 3,
"StateHash": 4,
"BlockHash": 5,
"AccountZero": 6,
"ChainHeight": 7,
"PreviousBlockHash": 8,
"CallingGraph": 9,
"TxResult": 10,
"CanonicalHash": 11,
"CurrentHash": 12,
"GenesisHash": 13,
"BlockHeaderHash": 14,
"BlockBodyHash": 15
}
},
"SInt32Value": {
"fields": {
"value": {
"type": "sint32",
"id": 1
}
}
},
"SInt64Value": {
"fields": {
"value": {
"type": "sint64",
"id": 1
}
}
},
"Transaction": {
"fields": {
"From": {
"type": "Address",
"id": 1
},
"To": {
"type": "Address",
"id": 2
},
"RefBlockNumber": {
"type": "uint64",
"id": 3
},
"RefBlockPrefix": {
"type": "bytes",
"id": 4
},
"IncrementId": {
"type": "uint64",
"id": 5
},
"MethodName": {
"type": "string",
"id": 6
},
"Params": {
"type": "bytes",
"id": 7
},
"Fee": {
"type": "uint64",
"id": 8
},
"Sigs": {
"rule": "repeated",
"type": "bytes",
"id": 9
},
"Type": {
"type": "TransactionType",
"id": 10
},
"Time": {
"type": "google.protobuf.Timestamp",
"id": 11
}
}
},
"TransactionReceipt": {
"fields": {
"TransactionId": {
"type": "Hash",
"id": 1
},
"Transaction": {
"type": "Transaction",
"id": 2
},
"SignatureSt": {
"type": "SignatureStatus",
"id": 3
},
"RefBlockSt": {
"type": "RefBlockStatus",
"id": 4
},
"Status": {
"type": "TransactionStatus",
"id": 5
},
"IsSystemTxn": {
"type": "bool",
"id": 6
},
"ExecutedBlockNumber": {
"type": "uint64",
"id": 7
}
},
"nested": {
"TransactionStatus": {
"values": {
"UnknownTransactionStatus": 0,
"TransactionExecuting": 1,
"TransactionExecuted": 2
}
},
"SignatureStatus": {
"values": {
"UnknownSignatureStatus": 0,
"SignatureValid": 1,
"SignatureInvalid": -1
}
},
"RefBlockStatus": {
"values": {
"UnknownRefBlockStatus": 0,
"RefBlockValid": 1,
"RefBlockInvalid": -1,
"RefBlockExpired": -2,
"FutureRefBlock": -3
}
}
}
},
"StatePath": {
"fields": {
"Path": {
"rule": "repeated",
"type": "bytes",
"id": 1
}
}
},
"StateValue": {
"fields": {
"CurrentValue": {
"type": "bytes",
"id": 1
},
"OriginalValue": {
"type": "bytes",
"id": 2
}
}
},
"StateChange": {
"fields": {
"StatePath": {
"type": "StatePath",
"id": 1
},
"StateValue": {
"type": "StateValue",
"id": 2
}
}
},
"TransactionList": {
"fields": {
"Transactions": {
"rule": "repeated",
"type": "Transaction",
"id": 1
}
}
},
"TransactionType": {
"values": {
"ContractTransaction": 0,
"DposTransaction": 1,
"MsigTransaction": 2,
"ContractDeployTransaction": 3
}
},
"Status": {
"values": {
"NotExisted": 0,
"Pending": 1,
"Failed": 2,
"Mined": 3
}
},
"TransactionResult": {
"fields": {
"TransactionId": {
"type": "Hash",
"id": 1
},
"Status": {
"type": "Status",
"id": 2
},
"Logs": {
"rule": "repeated",
"type": "LogEvent",
"id": 3
},
"Bloom": {
"type": "bytes",
"id": 4
},
"RetVal": {
"type": "bytes",
"id": 5
},
"BlockNumber": {
"type": "uint64",
"id": 6
},
"BlockHash": {
"type": "Hash",
"id": 7
},
"Index": {
"type": "int32",
"id": 8
},
"StateHash": {
"type": "Hash",
"id": 9
},
"DeferredTxnId": {
"type": "Hash",
"id": 10
}
}
},
"ExecutionStatus": {
"values": {
"Undefined": 0,
"ExecutedButNotCommitted": 1,
"ExecutedAndCommitted": 2,
"Canceled": -1,
"SystemError": -2,
"ContractError": -10,
"ExceededMaxCallDepth": -11
}
},
"TransactionTrace": {
"fields": {
"TransactionId": {
"type": "Hash",
"id": 1
},
"RetVal": {
"type": "RetVal",
"id": 2
},
"StdOut": {
"type": "string",
"id": 3
},
"StdErr": {
"type": "string",
"id": 4
},
"StateHash": {
"type": "Hash",
"id": 5
},
"Logs": {
"rule": "repeated",
"type": "LogEvent",
"id": 6
},
"InlineTransactions": {
"rule": "repeated",
"type": "Transaction",
"id": 7
},
"InlineTraces": {
"rule": "repeated",
"type": "TransactionTrace",
"id": 8
},
"StateChanges": {
"rule": "repeated",
"type": "StateChange",
"id": 9
},
"Elapsed": {
"type": "int64",
"id": 10
},
"ExecutionStatus": {
"type": "ExecutionStatus",
"id": 11
},
"DeferredTransaction": {
"type": "bytes",
"id": 12
}
}
},
"LogEvent": {
"fields": {
"Address": {
"type": "Address",
"id": 1
},
"Topics": {
"rule": "repeated",
"type": "bytes",
"id": 2
},
"Data": {
"type": "bytes",
"id": 3
}
}
},
"RetVal": {
"fields": {
"Type": {
"type": "RetType",
"id": 1
},
"Data": {
"type": "bytes",
"id": 2
}
},
"nested": {
"RetType": {
"values": {
"Void": 0,
"Bool": 1,
"Int32": 2,
"UInt32": 3,
"Int64": 4,
"UInt64": 5,
"String": 6,
"Bytes": 7,
"PbMessage": 8,
"UserType": 9
}
}
}
},
"BlockHeaderList": {
"fields": {
"Headers": {
"rule": "repeated",
"type": "BlockHeader",
"id": 1
}
}
},
"BlockHeader": {
"fields": {
"Version": {
"type": "int32",
"id": 1
},
"PreviousBlockHash": {
"type": "Hash",
"id": 2
},
"MerkleTreeRootOfTransactions": {
"type": "Hash",
"id": 3
},
"MerkleTreeRootOfWorldState": {
"type": "Hash",
"id": 4
},
"Bloom": {
"type": "bytes",
"id": 5
},
"Index": {
"type": "uint64",
"id": 6
},
"Sig": {
"type": "bytes",
"id": 7
},
"P": {
"type": "bytes",
"id": 8
},
"Time": {
"type": "google.protobuf.Timestamp",
"id": 9
},
"ChainId": {
"type": "Hash",
"id": 10
},
"SideChainTransactionsRoot": {
"type": "Hash",
"id": 11
}
}
},
"BlockBody": {
"fields": {
"BlockHeader": {
"type": "Hash",
"id": 1
},
"Transactions": {
"rule": "repeated",
"type": "Hash",
"id": 2
},
"TransactionList": {
"rule": "repeated",
"type": "Transaction",
"id": 3
},
"IndexedInfo": {
"rule": "repeated",
"type": "SideChainBlockInfo",
"id": 4
}
}
},
"Block": {
"fields": {
"Header": {
"type": "BlockHeader",
"id": 1
},
"Body": {
"type": "BlockBody",
"id": 2
}
}
},
"SmartContractRegistration": {
"fields": {
"Category": {
"type": "int32",
"id": 1
},
"ContractHash": {
"type": "Hash",
"id": 2
},
"ContractBytes": {
"type": "bytes",
"id": 3
},
"SerialNumber": {
"type": "uint64",
"id": 4
}
}
},
"SmartContractDeployment": {
"fields": {
"ContractHash": {
"type": "Hash",
"id": 1
},
"Caller": {
"type": "Hash",
"id": 2
},
"ConstructParams": {
"type": "bytes",
"id": 3
},
"IncrementId": {
"type": "uint64",
"id": 4
}
}
},
"Parameters": {
"fields": {
"Params": {
"rule": "repeated",
"type": "Param",
"id": 1
}
}
},
"Param": {
"oneofs": {
"data": {
"oneof": [
"intVal",
"uintVal",
"longVal",
"ulongVal",
"boolVal",
"bytesVal",
"strVal",
"dVal",
"hashVal",
"registerVal",
"deploymentVal"
]
}
},
"fields": {
"intVal": {
"type": "int32",
"id": 1
},
"uintVal": {
"type": "uint32",
"id": 2
},
"longVal": {
"type": "int64",
"id": 3
},
"ulongVal": {
"type": "uint64",
"id": 4
},
"boolVal": {
"type": "bool",
"id": 5
},
"bytesVal": {
"type": "bytes",
"id": 6
},
"strVal": {
"type": "string",
"id": 7
},
"dVal": {
"type": "double",
"id": 8
},
"hashVal": {
"type": "Hash",
"id": 9
},
"registerVal": {
"type": "SmartContractRegistration",
"id": 10
},
"deploymentVal": {
"type": "SmartContractDeployment",
"id": 11
}
}
},
"SmartContractInvokeContext": {
"fields": {
"Caller": {
"type": "Hash",
"id": 1
},
"IncrementId": {
"type": "uint64",
"id": 2
},
"MethodName": {
"type": "string",
"id": 3
},
"Params": {
"type": "bytes",
"id": 4
}
}
},
"DataItem": {
"fields": {
"ResourcePath": {
"type": "Hash",
"id": 1
},
"ResourcePointer": {
"type": "Hash",
"id": 2
},
"StateMerkleTreeLeaf": {
"type": "Hash",
"id": 3
}
}
},
"WorldState": {
"fields": {
"Data": {
"rule": "repeated",
"type": "DataItem",
"id": 1
}
}
},
"Chain": {
"fields": {
"Id": {
"type": "Hash",
"id": 1
},
"GenesisBlockHash": {
"type": "Hash",
"id": 2
}
}
},
"DataAccessMode": {
"values": {
"ReadOnlyAccountSharing": 0,
"ReadWriteAccountSharing": 1,
"AccountSpecific": 2
}
},
"Key": {
"fields": {
"Value": {
"type": "bytes",
"id": 1
},
"type": {
"type": "string",
"id": 2
},
"HashType": {
"type": "uint32",
"id": 3
}
}
},
"DataPath": {
"fields": {
"ChainId": {
"type": "Hash",
"id": 1
},
"BlockHeight": {
"type": "uint64",
"id": 2
},
"BlockProducerAddress": {
"type": "Address",
"id": 3
},
"ContractAddress": {
"type": "Address",
"id": 4
},
"DataProviderHash": {
"type": "Hash",
"id": 5
},
"KeyHash": {
"type": "Hash",
"id": 6
},
"StatePath": {
"type": "StatePath",
"id": 7
}
}
},
"BinaryMerkleTree": {
"fields": {
"Nodes": {
"rule": "repeated",
"type": "Hash",
"id": 1
},
"Root": {
"type": "Hash",
"id": 2
},
"LeafCount": {
"type": "int32",
"id": 3
}
}
},
"StringList": {
"fields": {
"Values": {
"rule": "repeated",
"type": "string",
"id": 1
}
}
},
"SideChainBlockInfo": {
"fields": {
"Height": {
"type": "uint64",
"id": 1
},
"BlockHeaderHash": {
"type": "Hash",
"id": 2
},
"TransactionMKRoot": {
"type": "Hash",
"id": 3
},
"ChainId": {
"type": "Hash",
"id": 4
}
}
},
"ParentChainBlockInfo": {
"fields": {
"Root": {
"type": "ParentChainBlockRootInfo",
"id": 1
},
"IndexedBlockInfo": {
"keyType": "uint64",
"type": "MerklePath",
"id": 2
}
}
},
"ParentChainBlockRootInfo": {
"fields": {
"Height": {
"type": "uint64",
"id": 1
},
"SideChainBlockHeadersRoot": {
"type": "Hash",
"id": 2
},
"SideChainTransactionsRoot": {
"type": "Hash",
"id": 3
},
"ChainId": {
"type": "Hash",
"id": 4
}
}
},
"MerklePath": {
"f