Skip to content

Commit c41e54c

Browse files
committed
Merged conflicts with master on the CLI
1 parent ca3d6be commit c41e54c

File tree

8 files changed

+391
-1138
lines changed

8 files changed

+391
-1138
lines changed

CLI/commands/ST20Generator.js

Lines changed: 11 additions & 369 deletions
Large diffs are not rendered by default.

CLI/commands/common/common_functions.js

Lines changed: 7 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ function getFinalOptions(options) {
3434
from: Issuer,
3535
gasPrice: defaultGasPrice,
3636
value: undefined,
37-
factor: 1.2
37+
factor: 1.2,
38+
minNonce: 0
3839
}
3940
return Object.assign(defaultOptions, options)
4041
};
4142

4243
async function getGasLimit(options, action) {
43-
let block = await web3.eth.getBlock("latest");
44+
let block = await web3.eth.getBlock('latest');
4445
let networkGasLimit = block.gasLimit;
4546
let gas = Math.round(options.factor * (await action.estimateGas({ from: options.from.address, value: options.value })));
4647
return (gas > networkGasLimit) ? networkGasLimit : gas;
@@ -98,101 +99,21 @@ module.exports = {
9899
%%%.
99100
`);
100101
},
101-
<<<<<<< HEAD
102+
getNonce: async function (from) {
103+
return (await web3.eth.getTransactionCount(from.address, "pending"));
104+
},
102105
sendTransaction: async function (action, options) {
103106
await checkPermissions(action);
104107

105108
options = getFinalOptions(options);
106109
let gasLimit = await getGasLimit(options, action);
107-
=======
108-
getNonce: async function(from) {
109-
return (await web3.eth.getTransactionCount(from.address, "pending"));
110-
},
111-
sendTransaction: async function (from, action, gasPrice, value, factor) {
112-
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);
113-
114-
//NOTE this is a condition to verify if the transaction comes from a module or not.
115-
if (contractRegistry.methods.hasOwnProperty('factory')) {
116-
let moduleAddress = await contractRegistry.methods.factory().call();
117-
let moduleRegistry = await connect(abis.moduleFactory(), moduleAddress)
118-
let parentModule = await moduleRegistry.methods.getName().call();
119-
let result = await checkPermission(web3.utils.hexToUtf8(parentModule), action._method.name, contractRegistry);
120-
if (!result) {
121-
console.log("You haven't the right permissions to execute this method.");
122-
process.exit(0);
123-
}
124-
}
125-
126-
if (typeof factor === 'undefined') factor = 1.2;
127-
128-
let block = await web3.eth.getBlock("latest");
129-
let networkGasLimit = block.gasLimit;
130-
let gas = Math.round(factor * (await action.estimateGas({ from: from.address, value: value})));
131-
if (gas > networkGasLimit) gas = networkGasLimit;
132-
133-
console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gas} ----`));
134-
135-
let nonce = await web3.eth.getTransactionCount(from.address);
136-
let abi = action.encodeABI();
137-
let parameter = {
138-
from: from.address,
139-
to: action._parent._address,
140-
data: abi,
141-
gasLimit: gas,
142-
gasPrice: gasPrice,
143-
nonce: nonce,
144-
value: web3.utils.toHex(value)
145-
};
146-
147-
const transaction = new Tx(parameter);
148-
transaction.sign(Buffer.from(from.privateKey.replace('0x', ''), 'hex'));
149-
return await web3.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex'))
150-
.on('transactionHash', function(hash){
151-
console.log(`
152-
Your transaction is being processed. Please wait...
153-
TxHash: ${hash}`
154-
);
155-
})
156-
.on('receipt', function(receipt){
157-
console.log(`
158-
Congratulations! The transaction was successfully completed.
159-
Gas used: ${receipt.gasUsed} - Gas spent: ${web3.utils.fromWei((new web3.utils.BN(gasPrice)).mul(new web3.utils.BN(receipt.gasUsed)))} Ether
160-
Review it on Etherscan.
161-
TxHash: ${receipt.transactionHash}\n`
162-
);
163-
});
164-
},
165-
sendTransactionWithNonce: async function (from, action, gasPrice, minNonce, value, factor) {
166-
let contractRegistry = await connect(action._parent.options.jsonInterface, action._parent._address);
167-
168-
//NOTE this is a condition to verify if the transaction comes from a module or not.
169-
if (contractRegistry.methods.hasOwnProperty('factory')) {
170-
let moduleAddress = await contractRegistry.methods.factory().call();
171-
let moduleRegistry = await connect(abis.moduleFactory(), moduleAddress)
172-
let parentModule = await moduleRegistry.methods.getName().call();
173-
let result = await checkPermission(web3.utils.hexToUtf8(parentModule), action._method.name, contractRegistry);
174-
if (!result) {
175-
console.log("You haven't the right permissions to execute this method.");
176-
process.exit(0);
177-
}
178-
}
179-
if (typeof factor === 'undefined') factor = 1.2;
180-
181-
let block = await web3.eth.getBlock("latest");
182-
let networkGasLimit = block.gasLimit;
183-
>>>>>>> master-dev-2.1
184110

185111
console.log(chalk.black.bgYellowBright(`---- Transaction executed: ${action._method.name} - Gas limit provided: ${gasLimit} ----`));
186112

187-
<<<<<<< HEAD
188113
let nonce = await web3.eth.getTransactionCount(options.from.address);
189-
=======
190-
let nonce = await web3.eth.getTransactionCount(from.address);
191-
192-
if (nonce < minNonce) {
114+
if (nonce < options.minNonce) {
193115
nonce = minNonce;
194116
}
195-
>>>>>>> master-dev-2.1
196117
let abi = action.encodeABI();
197118
let parameter = {
198119
from: options.from.address,

CLI/commands/common/global.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const constants = require('./constants');
33

44
global.web3, global.Issuer, global.defaultGasPrice, global.remoteNetwork;
55

6-
function getGasPrice (networkId) {
7-
<<<<<<< HEAD
6+
function getGasPrice(networkId) {
87
let gasPrice;
98
switch (networkId) {
109
case 1: //Mainnet
@@ -24,25 +23,6 @@ function getGasPrice (networkId) {
2423
}
2524
return gasPrice;
2625
}
27-
=======
28-
let gasPrice;
29-
switch (networkId) {
30-
case 1: //Mainnet
31-
gasPrice = 20000000000;
32-
break;
33-
case 3: //Ropsten
34-
gasPrice = 50000000000;
35-
break;
36-
case 15: //Ganache
37-
gasPrice = 50000000000;
38-
break;
39-
case 42: //Kovan
40-
gasPrice = 5000000000;
41-
break;
42-
default:
43-
throw new Error('Network ID not identified');
44-
}
45-
>>>>>>> master-dev-2.1
4626

4727
function providerValidator(url) {
4828
var expression = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g;
@@ -56,7 +36,7 @@ async function httpProvider(url, file) {
5636
}
5737

5838
module.exports = {
59-
initialize: async function(network) {
39+
initialize: async function (network) {
6040
remoteNetwork = network;
6141
if (typeof web3 === 'undefined' || typeof Issuer === 'undefined' || typeof defaultGasPrice === 'undefined') {
6242
if (typeof remoteNetwork !== 'undefined') {

0 commit comments

Comments
 (0)