diff --git a/.gitignore b/.gitignore index 3fcdf83..c5a3d01 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ typings/ .next package-lock.json +.DS_Store # Snak project folders diff --git a/README.md b/README.md index b3a4561..734d104 100644 --- a/README.md +++ b/README.md @@ -153,18 +153,18 @@ Commands: No need to initialize a project before using this command. - transact|tx [options]
+ transact|tx [options]
(Unsafe!) Do regular transaction to a contract, you need pass the private key of sender and address of contract you need to initialize a project before using this command. - bond|bnd [options] - (safe) Do Bond transaction, you need pass the validator publickey, stake amount, transaction fee, and private key of sender + bond|bnd [options] + (safe) Do Bond transaction, you need pass the validator publickey, stake amount and private key of sender you may need to initialize a project before using this command. - unbond|ubnd [options]
- (safe) Do Unbond transaction, you need pass account address, stake amount, transaction fee and private key of the validator + unbond|ubnd [options]
+ (safe) Do Unbond transaction, you need pass account address, stake amount and private key of the validator you may need to initialize a project before using this command. Note: you should be a validator to do unbond transaction. @@ -180,7 +180,7 @@ Commands: permission|perm [options]
- (safe) Do regular permission transaction, you need to pass the permission value and address of the receiver, private key of sender + (safe) Do regular permission transaction, you need to pass the permission value and address of the receiver, private key of any one of the validator you may need to initialize a project before using this command. diff --git a/actions.js b/actions.js index af71160..1636786 100644 --- a/actions.js +++ b/actions.js @@ -420,16 +420,16 @@ module.exports = class Action { }); } - broadcastBond(pubKey,amount,fee,privKey){ - return this._txHandler().bond(pubKey,amount,fee,privKey).then(data =>{ + broadcastBond(pubKey,amount,privKey){ + return this._txHandler().bond(pubKey,amount,privKey).then(data =>{ logger.console("Safe Bond Tx result :\n" + JSON.stringify(data,null,4)); }).catch(ex => { logger.error(ex); }); } - broadcastUnbond(address,amount,fee,privKey){ - return this._txHandler().unbond(address,amount,fee,privKey).then(data =>{ + broadcastUnbond(address,amount,privKey){ + return this._txHandler().unbond(address,amount,privKey).then(data =>{ logger.console("Safe Unbond Tx result :\n" + JSON.stringify(data,null,4)); }).catch(ex => { logger.error(ex); diff --git a/index.js b/index.js index bdadafe..9320312 100755 --- a/index.js +++ b/index.js @@ -89,7 +89,7 @@ program .action((address) => actions.validatorInfo(address)); program - .command('list_accounts') + .command('list_accounts') .alias('lacnt') .description('\nLoad all accounts\ \nyou need to initialize a project before using this command.\n\n') @@ -143,28 +143,28 @@ program .alias('tx') .description('\n(Unsafe!) Do regular transaction to a contract, you need pass the private key of sender and address of contract\ \nyou need to initialize a project before using this command.\n\n') - .action((priv_key,data,address,fee,gas_limit,cmd) => actions.transact(priv_key,data,address,fee,gas_limit,cmd.unsafe)); + .action((priv_key,data,address,gas_limit,cmd) => actions.transact(priv_key,data,address,fee,gas_limit,cmd.unsafe)); program - .command('bond ') - .option('-u, --unsafe', 'unsafe transaction') //TODO (unsafe should be implemented using privatekey) + .command('bond ') + .option('-u, --unsafe', 'unsafe transaction') //TODO .alias('bnd') - .description('\n(safe) Do Bond transaction, you need pass the validator publickey, stake amount, transaction fee, and private key of sender \ + .description('\n(safe) Do Bond transaction, you need pass the validator publickey, stake amount and private key of sender \ \nyou may need to initialize a project before using this command.\n\n') - .action((public_key,amount,fee,priv_key) => actions.broadcastBond(public_key,parseInt(amount),parseInt(fee),priv_key)); + .action((public_key,amount,priv_key) => actions.broadcastBond(public_key,parseInt(amount), priv_key)); program - .command('unbond
') + .command('unbond
') .option('-u, --unsafe', 'unsafe sending transaction') .alias('ubnd') - .description('\n(safe) Do Unbond transaction, you need pass account address, stake amount, transaction fee and private key of the validator \ + .description('\n(safe) Do Unbond transaction, you need pass account address, stake amount and private key of the validator \ \nyou may need to initialize a project before using this command.\ \nNote: you should be a validator to do unbond transaction.\n\n') - .action((address,amount,fee,priv_key) => actions.broadcastUnbond(address,parseInt(amount),parseInt(fee),priv_key)); + .action((address,amount,priv_key) => actions.broadcastUnbond(address,parseInt(amount),priv_key)); program .command('send
') - .option('-u, --unsafe', 'unsafe sending transaction') //TODO (unsafe should be implemented using privatekey) + .option('-u, --unsafe', 'unsafe sending transaction') //TODO .alias('snd') .description('\n(safe) Do regular transaction, you need to pass the address of the receiver, amount and the private key of sender \ \nyou may need to initialize a project before using this command.\n\n') @@ -172,19 +172,12 @@ program program .command('permission
') - .option('-u, --unsafe', 'unsafe sending transaction') //TODO (unsafe should be implemented using privatekey) + .option('-u, --unsafe', 'unsafe sending transaction') //TODO .alias('perm') - .description('\n(safe) Do regular permission transaction, you need to pass the permission value and address of the receiver, private key of sender \ + .description('\n(safe) Do regular permission transaction, you need to pass the permission value and address of the receiver, private key of validator \ \nyou may need to initialize a project before using this command.\n\n') .action((address,perm_value,priv_key) => actions.permission(address,perm_value,priv_key)); - program - .command('*') - .action(function(others){ - console.log('[Error] There isn\'t any command for "%s" \n\ - please type gnet -h for more helps.\n', others); - }); - program .command('call [parameters_list]') .alias('calf') @@ -249,6 +242,11 @@ program \nYou may need to initialize a project before using this command.\n\n") .action(() => actions.getConfig()); - + program + .command('*') + .action(function(others){ + console.log('[Error] There isn\'t any command for "%s" \n\ + please type gnet -h for more helps.\n', others); + }); program.parse(process.argv); diff --git a/libs/transactions/transaction.js b/libs/transactions/transaction.js index 77c8a6d..f855345 100644 --- a/libs/transactions/transaction.js +++ b/libs/transactions/transaction.js @@ -1,106 +1,59 @@ -'use strict' - +"use strict"; var Keys = require('../keys'); var keys = new Keys; - -const SEND_TX_TYPE = 0x1 -const BOND_TX_TYPE = 0x3; -const UNBOND_TX_TYPE = 0x4; -const PERMISSION_TX_TYPE = 0x5; - module.exports = class Transaction { - - constructor(intergallactic) { - this.igc = intergallactic; - } - - send(address, amount, priv_key) { - const account = keys.getAccountInfo(priv_key) - - const myTx = { - from: [{ - address: account.acAddress, - amount: amount - }], - to: [{ - address: address, - amount: amount - }] - }; - - return this.signAndBroadcast(myTx, priv_key, SEND_TX_TYPE) - } - - permission(address,perm_value,priv_key) { - const account = keys.getAccountInfo(priv_key) - const myTx = { - from: { - address: account.acAddress, - amount: 0 - }, - to: { - address: address, - amount: 0 - }, - permissions: perm_value, - set: true - } - - return this.signAndBroadcast(myTx, priv_key,PERMISSION_TX_TYPE) - } - - transact() { - let myTx = this.buildTxn(fromAddress, toAddress, amount) - } - - bond(pubKey,amount,fee,priv_key) { - const account = keys.getAccountInfo(priv_key) - const vaAccount = keys.getInfoByPublicKey(pubKey) - - const myTx = { - from: { - address: account.acAddress, - amount: amount - }, - to: { - address: vaAccount.vaAddress, - amount: amount - }, - publicKey: pubKey, - gasLimit: fee - }; - - return this.signAndBroadcast(myTx, priv_key, BOND_TX_TYPE) - } - - unbond(address,amount,fee,priv_key) { - const account = keys.getAccountInfo(priv_key) - - const myTx = { - from: { - address: account.vaAddress, - amount: amount - }, - to: { - address: address, - amount: amount - }, - gasLimit: fee - }; - - return this.signAndBroadcast(myTx, priv_key, UNBOND_TX_TYPE) - } - - randomTransact() { - //TODO - } - - signAndBroadcast(txnObject, priv_key, txnType) { - - const newTxn = new this.igc.Transaction(txnObject, { type: txnType }); - - return newTxn.signNBroadcast(priv_key).then(data => { - return (data); - }) - } -} \ No newline at end of file + constructor(intergallactic) { + this.igc = intergallactic; + } + + send(address, amount, priv_key) { + const myTx = { + to: address, + amount: amount + }; + const newTxn = new this.igc.Transaction(myTx); + return newTxn.send(priv_key); + } + + permission(address, perm_value, priv_key) { + const myTx = { + to: address, + amount: 0, + permissions:perm_value, + set: true + }; + const newTxn = new this.igc.Transaction(myTx); + return newTxn.permission(priv_key); + } + + bond(pubKey, amount, priv_key) { + const vaAccount = keys.getInfoByPublicKey(pubKey) + const myTx = { + to: vaAccount.vaAddress, + amount: amount, + publicKey: pubKey + }; + const newTxn = new this.igc.Transaction(myTx); + return newTxn.bond(priv_key); + } + + unbond(address, amount, priv_key) { + const myTx = { + to: address, + amount: amount + }; + const newTxn = new this.igc.Transaction(myTx); + return newTxn.send(priv_key); + } + + call(to, gaslimit, amount, data) { + const myTx = { + to: to, + gasLimit: gaslimit, + amount: amount, + data: data + }; + const newTxn = new this.igc.Transaction(myTx); + return newTxn.call(priv_key); + } +}; diff --git a/package.json b/package.json index bdc3280..908aaa4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dependencies": { "commander": "^2.9.0", "gallactickeys": "^0.2.2", - "intergallactic": "github:gallactic/intergallactic#dev", + "intergallactic": "^0.1.0", "md5": "2.2.1", "mocha": "^5.2.0", "promise": "8.0.1",