eth-contract-class
Advanced tools
Comparing version 0.0.13-beta.1 to 0.0.13-beta.2
// embark plugin to use eth-contract-class | ||
const generateClass = require('../lib/generateClass').default; | ||
module.exports = function() { | ||
this.registerTestContractFactory(function testContractFactory(contractRecipe, web3) { | ||
if (!contractRecipe.code) return null; | ||
const ContractClass = generateClass(contractRecipe.abiDefinition, contractRecipe.code); | ||
const contract = new ContractClass(web3, contractRecipe.deployedAddress); | ||
module.exports = Embark => { | ||
Embark.events.on('runcode:ready', () => { | ||
Embark.events.emit('runcode:register', 'generateClass', require('eth-contract-class'), () => { | ||
Embark.registerTestContractFactory(function testContractFactory(contractRecipe, web3) { | ||
if (!contractRecipe.code) return null; | ||
const generateClass = require('eth-contract-class').default; | ||
const ContractClass = generateClass(contractRecipe.abiDefinition, contractRecipe.code); | ||
const contract = new ContractClass(web3, contractRecipe.deployedAddress); | ||
contract.$runtimeByteCode = '0x' + contractRecipe.runtimeBytecode; | ||
contract.$runtimeByteCode = '0x' + contractRecipe.runtimeBytecode; | ||
// embark creates a empty Object for contracts when using embark.require('Embark/contracts/*') | ||
// then uses Object.setPrototypeOf(contractObject, contractFactoryResult) to "populate" the | ||
// object. Unfortunately this will ensure that the contract instance is not callable directly | ||
// so we instantiate the contract instance here & return the object. | ||
// we provide the `.at` function here so we can provide a way to get a new Contract instance | ||
return Object.assign(contract, { | ||
new: (...args) => ContractClass.new(web3, ...args), | ||
at: address => new ContractClass(web3, address), | ||
// embark creates a empty Object for contracts when using embark.require('Embark/contracts/*') | ||
// then uses Object.setPrototypeOf(contractObject, contractFactoryResult) to "populate" the | ||
// object. Unfortunately this will ensure that the contract instance is not callable directly | ||
// so we instantiate the contract instance here & return the object. | ||
// we provide the `.at` function here so we can provide a way to get a new Contract instance | ||
return Object.assign(contract, { | ||
new: (...args) => ContractClass.new(web3, ...args), | ||
at: address => new ContractClass(web3, address), | ||
}); | ||
}); | ||
Embark.registerCustomContractGenerator(contract => { | ||
return ` | ||
${contract.className} = generateClass(${JSON.stringify(contract.abiDefinition)}, '${ | ||
contract.code | ||
}'); | ||
${contract.className}Instance = new ${contract.className}(web3, '${ | ||
contract.deployedAddress | ||
}'); | ||
`; | ||
}); | ||
}); | ||
}); | ||
this.registerCustomContractGenerator(contract => { | ||
return ` | ||
generateClass = require('eth-contract-class').default; | ||
${contract.className} = generateClass(${JSON.stringify(contract.abiDefinition)}, '${ | ||
contract.code | ||
}'); | ||
${contract.className}Instance = new ${contract.className}(web3, '${ | ||
contract.deployedAddress | ||
}'); | ||
`; | ||
}); | ||
}; |
{ | ||
"name": "eth-contract-class", | ||
"version": "0.0.13-beta.1", | ||
"version": "0.0.13-beta.2", | ||
"description": "generate js wrapper class around an ethereum contract", | ||
@@ -5,0 +5,0 @@ "main": "lib/generateClass.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
20792
181
1