eth-contract-class
Advanced tools
Comparing version 0.0.13-beta.2 to 0.0.13-beta.3
// embark plugin to use eth-contract-class | ||
const generateClass = require('../lib/generateClass').default; | ||
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); | ||
Embark.registerTestContractFactory(function testContractFactory(contractRecipe, web3) { | ||
if (!contractRecipe.code) return null; | ||
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, { | ||
deploy: (...args) => ContractClass.new(web3, ...args), | ||
at: address => new ContractClass(web3, address), | ||
}); | ||
}); | ||
// For some reason this is called multiple times, so we use .once | ||
Embark.events.once('blockchain:ready', () => { | ||
Embark.events.emit('runcode:register', 'generateClass', generateClass, () => { | ||
Embark.registerCustomContractGenerator(contract => { | ||
return ` | ||
${contract.className} = generateClass(${JSON.stringify(contract.abiDefinition)}, '${ | ||
${contract.className} = new (generateClass(${JSON.stringify(contract.abiDefinition)}, '${ | ||
contract.code | ||
}'); | ||
${contract.className}Instance = new ${contract.className}(web3, '${ | ||
}'))(web3, '${contract.deployedAddress}');`; | ||
}); | ||
}); | ||
}); | ||
Embark.registerContractsGeneration(function(options) { | ||
const contractGenerations = []; | ||
Object.keys(options.contracts).map(className => { | ||
const contract = options.contracts[className]; | ||
const abi = JSON.stringify(contract.abiDefinition); | ||
contractGenerations.push( | ||
` | ||
/* global web3 */ | ||
"use strict"; | ||
// Loading EmbarkJS will make web3 globally available | ||
const isNode = (typeof process !== 'undefined' && process.versions && process.versions.node); | ||
const EmbarkJSNode = isNode && require('../embarkjs.node'); | ||
let EmbarkJSBrowser; | ||
try { | ||
EmbarkJSBrowser = require('../embarkjs').default; | ||
} catch(e) {}; | ||
const generateClass = require('eth-contract-class').default; | ||
let ${className} = new (generateClass(${abi}, '${contract.code}'))(web3, '${ | ||
contract.deployedAddress | ||
}'); | ||
`; | ||
}); | ||
module.exports = ${className}; | ||
`, | ||
); | ||
}); | ||
return contractGenerations.join('\n'); | ||
}); | ||
}; |
{ | ||
"name": "eth-contract-class", | ||
"version": "0.0.13-beta.2", | ||
"version": "0.0.13-beta.3", | ||
"description": "generate js wrapper class around an ethereum contract", | ||
"main": "lib/generateClass.js", | ||
"directories": { | ||
"lib": "lib" | ||
"lib": "lib", | ||
"embark": "embark" | ||
}, | ||
@@ -9,0 +10,0 @@ "scripts": { |
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
21749
204
0