aion-web3-avm-contract
Advanced tools
Comparing version 1.2.6-beta.0 to 1.2.6-beta.1
{ | ||
"name": "aion-web3-avm-contract", | ||
"namespace": "aion", | ||
"version": "1.2.6-beta.0", | ||
"version": "1.2.6-beta.1", | ||
"description": "Web3 module for using the abi to use AVM Contracts", | ||
@@ -11,3 +11,3 @@ "repository": "https://github.com/aionnetwork/aion_web3/tree/avm-support-update/packages/web3-avm-contract", | ||
"aion-lib": "1.1.4", | ||
"aion-web3-avm-abi": "1.2.6-beta.0", | ||
"aion-web3-avm-abi": "1.2.6-beta.1", | ||
"aion-web3-utils": "1.1.4", | ||
@@ -18,3 +18,3 @@ "bn.js": "^4.11.8", | ||
}, | ||
"gitHead": "f434c5ca72653a24c649f9365f5b773f8409a7ad" | ||
"gitHead": "3036fcf251ea9470887775635243742a0eabe99b" | ||
} |
175
src/index.js
@@ -57,2 +57,7 @@ /* | ||
this._gasPrice = 10000000000;//10000000000 | ||
this._gas = 2000000; | ||
this._value = 0; | ||
this._nonce = null; | ||
this._provider = null; | ||
@@ -68,4 +73,4 @@ | ||
data: data, | ||
gasPrice: 2000000, | ||
gas: 5000000, | ||
gasPrice: this._gasPrice, | ||
gas: this._gas, | ||
type: '0x1' | ||
@@ -78,14 +83,19 @@ }; | ||
this.sendTransaction = async (txObject,returnType=null) => { | ||
/** | ||
*@desc signs and send a transaction | ||
*@param accepts a transaction data object | ||
*@return returns the transaction data or false on error | ||
**/ | ||
this.sendTransaction = async (txObject) => { | ||
let signedTx = await this.instance.eth.accounts.signTransaction(txObject, this._key); | ||
//txn:returned transaction object | ||
//output: return from the function | ||
let response = {txn:null,output:null}; | ||
try{ | ||
//send transaction | ||
let res = await this.instance.eth.sendSignedTransaction(signedTx.rawTransaction); | ||
if(returnType!==null){ | ||
let result = await this.instance.avm.contract.decode(returnType, res); | ||
return result; | ||
}else{ | ||
return true; | ||
} | ||
return res; | ||
@@ -100,2 +110,8 @@ }catch(err){ | ||
/** | ||
*@desc makes a call | ||
*@param accepts a transaction data object and return type | ||
*@return if return type is not null return the decoded data else return true or false if there is an error | ||
**/ | ||
this.call = async (txObject,returnType=null) => { | ||
@@ -113,3 +129,3 @@ | ||
console.log("Call Failed!", err); | ||
return false; | ||
return false; //may need to be improved for booleans | ||
} | ||
@@ -120,3 +136,91 @@ | ||
} | ||
/** | ||
*@desc get the current value set for gas | ||
*@param none | ||
*@return returns the value of _gas | ||
**/ | ||
getGas(){ | ||
return this._gas | ||
} | ||
setGas(gas=null){ | ||
if(gas!==null){ | ||
this._gas = gas; | ||
}else{ | ||
throw new Error('Invalid gas'); | ||
} | ||
} | ||
/** | ||
*@desc get the current value set for gas price | ||
*@param none | ||
*@return returns the value of _gasPrice | ||
**/ | ||
getGasPrice(){ | ||
return this._gasPrice | ||
} | ||
setGasPrice(gas=null){ | ||
if(gas!==null){ | ||
this._gasPrice = gas; | ||
}else{ | ||
throw new Error('Invalid gasPrice'); | ||
} | ||
} | ||
/** | ||
*@desc get the current value set for a transaction value field | ||
*@param none | ||
*@return returns the value of _value | ||
**/ | ||
getValue(){ | ||
return this._value | ||
} | ||
setValue(value=null){ | ||
if(value!==null){ | ||
this._value = value; | ||
}else{ | ||
throw new Error('Invalid gas'); | ||
} | ||
} | ||
//to be improved | ||
getNonce(){ | ||
return this._nonce | ||
} | ||
/** | ||
*@desc get the current value set for gas | ||
*@param none | ||
*@return returns the value of _gas | ||
**/ | ||
setNonce(nonce=null){ | ||
if(nonce!==null){ | ||
this._nonce = nonce; | ||
}else{ | ||
throw new Error('Invalid nonce'); | ||
} | ||
} | ||
/** | ||
*@desc set value from a provided transaction object | ||
*@param accepts an object with necessary fields | ||
*@return none | ||
**/ | ||
setTransactionObject(obj){ | ||
if(obj!==null){ | ||
if(obj.gas!==null){ | ||
this._gas = obj.gas; | ||
} | ||
if(obj.gasPrice!==null){ | ||
this._gasPrice = obj.gasPrice; | ||
} | ||
if(obj.value!==null){ | ||
this._value = obj.value; | ||
} | ||
if(obj.nonce!==null){ | ||
this._nonce = obj.nonce; | ||
} | ||
}else{ | ||
throw new Error('Invalid transaction object'); | ||
} | ||
} | ||
//assign default provider | ||
@@ -142,4 +246,8 @@ provider(provider=null){ | ||
//Prepare transaction object | ||
txnObj(address,contract,data,gasPrice=10000000000,gas=2000000,type='0x1'){ | ||
txnObj(address,contract,data,gasPrice=10000000000,gas=2000000,nonce=null,type='0x1'){ | ||
let g = this._gas; | ||
let gP = this._gasPrice; | ||
let v = this._value; | ||
let txObject = { | ||
@@ -149,6 +257,13 @@ from: address, | ||
data: data, | ||
gasPrice: gasPrice, | ||
gas: gas, | ||
gasPrice: gP,//gasPrice,// | ||
gas: g,//gas, | ||
value: v,//value | ||
type: type | ||
}; | ||
//console.log("HERE IS THE DATA >>>>", txObject.gasPrice,"##",txObject.gas,"##",txObject.value); | ||
//nonce is calculated so only set if user provide a figure | ||
if(nonce!==null){ | ||
txObject.nonce = nonce; | ||
} | ||
return txObject; | ||
@@ -161,3 +276,3 @@ } | ||
fns.forEach(function(fn){ | ||
//define call functions | ||
Object.defineProperty(obj.readOnly, fn.name,{ | ||
@@ -190,2 +305,3 @@ value: function(){ | ||
//define functions with send transaction | ||
Object.defineProperty(obj.transaction, fn.name,{ | ||
@@ -226,11 +342,19 @@ value: function(){ | ||
/** | ||
*@desc assign values and create function based on abi definition | ||
*@param takes the contract address, abi object, private key and web3 instance | ||
*@return none | ||
**/ | ||
initBinding(contractAddress=null, abi=null, key=null, instance=null) { | ||
if((contractAddress === null)||(abi === null)||(key === null)) { | ||
if((contractAddress === null)||(abi === null)) { | ||
throw new Error('Missing input parameter(s)'); | ||
} | ||
this._key = key; | ||
this._contract = contractAddress; | ||
this._interface = abi; | ||
if(key!==null){ | ||
this._key = key; | ||
} | ||
if(instance!==null){ | ||
@@ -241,4 +365,3 @@ this.instance = instance;//web3 intance to process transactions | ||
//TODO:Improve the following | ||
//console.log(this._provider); | ||
let ac = this.instance.eth.accounts.privateKeyToAccount(key); | ||
let ac = this.instance.eth.accounts.privateKeyToAccount(this._key); | ||
this._address = ac.address; | ||
@@ -250,5 +373,3 @@ | ||
} | ||
//mock method | ||
// Converts the Jar into a JarPath to be Encoded for Initialization | ||
@@ -261,2 +382,10 @@ deploy(jar) { | ||
// TODO: allow _jarPath creation from the browser | ||
// accepts file steam instaead of using fs.readFileSync(jar); | ||
clientDeploy(jar) { | ||
this._jarPath = jar //fs.readFileSync(jar); | ||
return this; | ||
} | ||
// Defines the Arguments of a AVM Contract's Initializer | ||
@@ -263,0 +392,0 @@ args(types, values) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49104
361
+ Addedaion-web3-avm-abi@1.2.6-beta.1(transitive)
- Removedaion-web3-avm-abi@1.2.6-beta.0(transitive)