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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typings/
.next

package-lock.json
.DS_Store


# Snak project folders
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ Commands:
No need to initialize a project before using this command.


transact|tx [options] <priv_key> <data> <address> <fee> <gas_limit>
transact|tx [options] <priv_key> <data> <address> <gas_limit>
(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] <public_key> <amount> <fee> <priv_key>
(safe) Do Bond transaction, you need pass the validator publickey, stake amount, transaction fee, and private key of sender
bond|bnd [options] <public_key> <amount> <priv_key>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove fee from these txs?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @ToniyaSundaram removed it, because currently intergallactic don't support fee feature yet

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b00f Yes it is in accordance with intergallactic

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fee = OutAmount - InAMount.
I think gnet should handle it. not intergallactic.

(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] <address> <amount> <fee> <priv_key>
(safe) Do Unbond transaction, you need pass account address, stake amount, transaction fee and private key of the validator
unbond|ubnd [options] <address> <amount> <priv_key>
(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.

Expand All @@ -180,7 +180,7 @@ Commands:


permission|perm [options] <address> <perm_value> <priv_key>
(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.


Expand Down
8 changes: 4 additions & 4 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 18 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -143,48 +143,41 @@ 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 <public_key> <amount> <fee> <priv_key>')
.option('-u, --unsafe', 'unsafe transaction') //TODO (unsafe should be implemented using privatekey)
.command('bond <public_key> <amount> <priv_key>')
.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 <address> <amount> <fee> <priv_key>')
.command('unbond <address> <amount> <priv_key>')
.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 <address> <amount> <priv_key>')
.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')
.action((address,amount,priv_key) => actions.send(address,parseInt(amount),priv_key));

program
.command('permission <address> <perm_value> <priv_key>')
.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 <contract_name> <function_name> [parameters_list]')
.alias('calf')
Expand Down Expand Up @@ -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);
159 changes: 56 additions & 103 deletions libs/transactions/transaction.js
Original file line number Diff line number Diff line change
@@ -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);
})
}
}
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);
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down