Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Geth.ValueChainWS = new Web3( VC_WS );
Geth.ValueChainWS._id = "VC_WS";
Geth.UtilityChain = new Web3(new Web3.providers.HttpProvider( UC_RPC ));
Geth.UtilityChain._id = "UC";
const DEF_DEPLOY_GAS = 4000000;
/** Helper for deploying a contract, if changed.
* @param {string} sender Address of sender
* @param {object} contract Contract JSON
* @param {string?} oldAddress Old address of this contract
* @param {Object} args Optional constructor arguments
* @returns {Promise} Resolves to address of contract
*/
Web3.prototype.deployContract = function(sender, contract, oldAddress, ...args) {
const minimumGasPrice = 100;
const forceRedeployContract = true;
const newCodeWithCtor = "0x" + contract.bin;
return Promise.resolve()
.then(_ => oldAddress ? this.eth.getCode(oldAddress) : "")
.then(oldCode => {
if (oldCode.length > 2 && newCodeWithCtor.endsWith(oldCode.substr(2)) && !forceRedeployContract ) {
// console.log("Skipped: contract body unchanged; constructor/args might have changed though!");
return oldAddress;
}
else {
return this.eth.personal.unlockAccount(sender)
// unlockAccount always fails under testrpc
.catch(err => console.error(this._id, err.message || err))
.then(success => {
const abi = JSON.parse(contract.abi);
// let _instances = {};
const OriginWeb3 = function() {
const oThis = this,
provider = oThis.ic().configStrategy.origin.provider;
console.log('OriginWeb3 provider', provider);
Web3.call(oThis, provider);
// Bind send method with signer.
oThis.bindSigner();
};
if (Web3.prototype) {
OriginWeb3.prototype = Object.create(Web3.prototype);
} else {
OriginWeb3.prototype = {};
}
OriginWeb3.prototype.constructor = OriginWeb3;
OriginWeb3.prototype.signerServiceInteract = function () {
const oThis = this;
let signers = oThis.ic().Signers();
return signers.getOriginSignerService();
};
signerServiceBinder( OriginWeb3.prototype );
InstanceComposer.registerShadowableClass(OriginWeb3, 'OriginWeb3');
import Promise from 'bluebird';
import Web3 from 'web3';
import _ from 'lodash';
const { asciiToHex, hexToAscii } =
// web3 1.X
Web3.utils || {
// web3 0.20.X
asciiToHex: Web3.prototype.fromAscii,
hexToAscii: Web3.prototype.toAscii,
};
export default class Voting {
constructor(contract) {
this.contract = contract;
const getCandidateList = Promise.promisify(
this.contract.getCandidateList.call,
{ context: this.contract.getCandidateList },
);
const totalVotesFor = Promise.promisify(this.contract.totalVotesFor.call, {
context: this.contract.totalVotesFor,
});
const voteForCandidate = Promise.promisify(
this.contract.voteForCandidate.sendTransaction,
async verifyCustomer(
// ownerAddress: string,
kycProviderAddress: string,
customerAddress: string,
countryJurisdiction: string,
divisionJurisdiction: string,
role: CustomerRole,
accredited: boolean,
expires: BigNumber,
) {
await this._contract.verifyCustomer(
customerAddress,
Web3.prototype.fromAscii(countryJurisdiction),
Web3.prototype.fromAscii(divisionJurisdiction),
new BigNumber(roleToNumber(role)),
accredited,
expires,
{
from: kycProviderAddress,
gas: 2500000,
},
);
}
const deployInfo = require('../helpers/deployInfo');
const Web3 = require('web3');
const Voting = artifacts.require('Voting');
const asciiToHex = (Web3.utils || {}).asciiToHex || Web3.prototype.fromAscii;
// ^^^ web3 1.x ^^^ web3 0.20.X
const candidates = ['Rama', 'Nick', 'Jose'];
module.exports = async deployer => {
await deployer.deploy(Voting, candidates.map(asciiToHex));
return deployInfo(deployer, Voting);
};
function buildSignature(params, privateKey) {
const priceWei = Web3.prototype.padLeft(Web3.prototype.toBigNumber(params.priceWei).toString(16), 64);
const text2sign =
params.wallet +
Buffer.concat([
Buffer.from(params.name, 'utf8'),
Buffer.from(params.country, 'utf8'),
Buffer.from(params.state, 'utf8'),
Buffer.from(params.city, 'utf8'),
Buffer.from(params.address, 'utf8'),
Buffer.from(params.zip, 'utf8'),
Buffer.from(priceWei, 'hex'),
Buffer.from(params.sha3cc.substr(2), 'hex'),
]).toString('hex');
return sign(text2sign, privateKey);
}
.then(function(result) {
logger.info(`[${oThis.endPointUrl}] heartbeat successful. latest block number:: ${result}`);
})
.catch(function(reason) {
logger.error(`[${oThis.endPointUrl}] WS ping failed. reason :: `, reason);
})
.then(function() {
setTimeout(function() {
oThis.providerHeartbeat();
}, oThis.providerOptions.providerPollingInterval);
});
}
};
//Take care of prototype
OSTWeb3.prototype = Object.assign(OSTWeb3Proto, Web3.prototype);
//Take care of all static properties of Web3.
(function() {
function addProp(prop) {
Object.defineProperty(OSTWeb3, prop, {
get: function() {
return Web3[prop];
},
set: function(newValue) {
Web3[prop] = newValue;
}
});
}
for (var prop in Web3) {
addProp(prop);
}
}
//__NOT_FOR_WEB__END__
Web3.call(oThis, provider, net);
//Bind send method with signer.
oThis.bindSignerService();
//Per-warm Connections.
let socketCnt = maxHttpScokets;
while (socketCnt--) {
oThis.eth.getBlockNumber();
}
};
if (Web3.prototype) {
ChainWeb3.prototype = Object.create(Web3.prototype);
} else {
ChainWeb3.prototype = {};
}
ChainWeb3.prototype.signerServiceInteract = function() {
const oThis = this;
let signers = oThis.ic().Signers();
return signers.getSignerService();
};
signerServiceBinder(ChainWeb3.prototype);
InstanceComposer.register(ChainWeb3, 'chainWeb3', true);
module.exports = ChainWeb3;
async createTemplate(
legalDelegateAddress: string,
offeringType: string,
issuerJurisdiction: string,
accredited: boolean,
kycProviderAddress: string,
details: string,
expires: BigNumber,
fee: BigNumber,
quorum: BigNumber,
vestingPeriod: BigNumber,
): Promise<template> {
const receipt = await this._contract.createTemplate(
offeringType,
Web3.prototype.fromAscii(issuerJurisdiction),
accredited,
kycProviderAddress,
details,
expires,
fee,
quorum,
vestingPeriod,
{
from: legalDelegateAddress,
gas: 4000000,
},
);
const logs = receipt.logs.filter(log => log.event === 'LogTemplateCreated');
if (logs.length === 0) {
throw new Error('createTemplate couldn\'t find an event log.');</template>
function hashSource(source) {
return Web3.prototype.sha3(source);
}