Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async sendTransaction (to, value, data, from) {
await this.assertContractExists()
if (!data) {
// erc20 transfer
data = this.generateErc20Transfer(to, value)
value = 0
to = ensure0x(this._contractAddress)
}
return this.getMethod('sendTransaction')(to, value, data, from)
}
createSwapScript (recipientAddress, refundAddress, secretHash, expiration) {
recipientAddress = remove0x(addressToString(recipientAddress))
refundAddress = remove0x(addressToString(refundAddress))
const dataSizeBase = 112
const redeemDestinationBase = 66
const refundDestinationBase = 89
const expirationHex = expiration.toString(16)
const expirationEncoded = padHexStart(expirationHex) // Pad with 0
const expirationSize = expirationEncoded.length / 2
const expirationPushOpcode = (0x60 - 1 + expirationSize).toString(16)
const redeemDestinationEncoded = (redeemDestinationBase + expirationSize).toString(16)
const refundDestinationEncoded = (refundDestinationBase + expirationSize).toString(16)
const dataSizeEncoded = (dataSizeBase + expirationSize).toString(16)
return [
// Constructor
'60', dataSizeEncoded, // PUSH1 {dataSizeEncoded}
createSwapScript (recipientAddress, refundAddress, secretHash, expiration) {
recipientAddress = remove0x(addressToString(recipientAddress))
refundAddress = remove0x(addressToString(refundAddress))
const dataSizeBase = 112
const redeemDestinationBase = 66
const refundDestinationBase = 89
const expirationHex = expiration.toString(16)
const expirationEncoded = padHexStart(expirationHex) // Pad with 0
const expirationSize = expirationEncoded.length / 2
const expirationPushOpcode = (0x60 - 1 + expirationSize).toString(16)
const redeemDestinationEncoded = (redeemDestinationBase + expirationSize).toString(16)
const refundDestinationEncoded = (refundDestinationBase + expirationSize).toString(16)
const dataSizeEncoded = (dataSizeBase + expirationSize).toString(16)
return [
// Constructor
'60', dataSizeEncoded, // PUSH1 {dataSizeEncoded}
'80', // DUP1
const refundSwapTransaction = block.transactions.find(transaction =>
transaction.to === initiationTransaction.contractAddress &&
transaction.input === remove0x(SOL_REFUND_FUNCTION) && // eslint-disable-line
block.timestamp >= expiration
)
if (from == null) {
const addresses = await this.getAddresses()
from = ensure0x(addresses[0].address)
}
value = BigNumber(value).toString(16)
const nonce = (parseInt((await this.getMethod('jsonrpc')('eth_getTransactionCount', this.wallet.getAddressString(), 'pending')), 16)).toString(16)
console.log('nonce')
console.log(nonce)
const gasPrice = await this.getMethod('jsonrpc')('eth_gasPrice')
const gasLimit = await this.getMethod('jsonrpc')('eth_estimateGas', { from, to, value: ensure0x(value), data: ensure0x(data), gasPrice: ensure0x(gasPrice)})
const txParams = {
nonce: ensure0x(nonce),
gasPrice: ensure0x(gasPrice),
gasLimit: ensure0x(gasLimit),
to,
value: ensure0x(value),
data: ensure0x(data),
chainId: networkId
}
const tx = new EthereumTx(txParams)
tx.sign(this.wallet.getPrivateKey())
const serializedTx = tx.serialize()
const txHash = await this.getMethod('jsonrpc')('eth_sendRawTransaction', ensure0x(serializedTx.toString('hex')))
return remove0x(txHash)
}
if (to != null) {
to = ensure0x(to)
}
if (from == null) {
const addresses = await this.getAddresses()
from = ensure0x(addresses[0].address)
}
value = BigNumber(value).toString(16)
const nonce = (parseInt((await this.getMethod('jsonrpc')('eth_getTransactionCount', this.wallet.getAddressString(), 'pending')), 16)).toString(16)
console.log('nonce')
console.log(nonce)
const gasPrice = await this.getMethod('jsonrpc')('eth_gasPrice')
const gasLimit = await this.getMethod('jsonrpc')('eth_estimateGas', { from, to, value: ensure0x(value), data: ensure0x(data), gasPrice: ensure0x(gasPrice)})
const txParams = {
nonce: ensure0x(nonce),
gasPrice: ensure0x(gasPrice),
gasLimit: ensure0x(gasLimit),
to,
value: ensure0x(value),
data: ensure0x(data),
chainId: networkId
}
const tx = new EthereumTx(txParams)
tx.sign(this.wallet.getPrivateKey())
const serializedTx = tx.serialize()
const txHash = await this.getMethod('jsonrpc')('eth_sendRawTransaction', ensure0x(serializedTx.toString('hex')))
async sendTransaction (to, value, data, from) {
const networkId = await this.getWalletNetworkId()
if (this._network) {
if (networkId !== this._network.networkId) {
throw new Error('Invalid MetaMask Network')
}
}
if (!from) {
const addresses = await this.getAddresses()
from = addressToString(addresses[0])
}
const tx = {
from: ensure0x(from),
value: ensure0x(BigNumber(value).toString(16))
}
if (to) tx.to = ensure0x(addressToString(to))
if (data) tx.data = ensure0x(data)
const txHash = await this.metamask('eth_sendTransaction', tx)
return remove0x(txHash)
}
async sendTransaction (to, value, data, from) {
if (!from) {
const addresses = await this.getAddresses()
from = addresses[0]
}
const tx = {
from: ensure0x(addressToString(from)),
to: to ? ensure0x(addressToString(from)) : null,
value: ensure0x(BigNumber(value).toString(16))
}
if (to) tx.to = ensure0x(addressToString(to))
if (data) {
tx.data = ensure0x(data)
tx.gas = ensure0x((await this.estimateGas(tx)).toString(16))
}
const txHash = await this.jsonrpc('eth_sendTransaction', tx)
return remove0x(txHash)
}
async getBiddingExpiration (contractAddress, block) {
const biddingExpiration = await this.getMethod('jsonrpc')('eth_call', { data: '0x9f2fe458', to: ensure0x(contractAddress) }, ensureBlockFormat(block))
return parseInt(biddingExpiration, 16)
}
addresses.map(address => this.getMethod('jsonrpc')(
'eth_call',
{
data: [
SOL_BALACE_OF_FUNCTION,
padHexStart(remove0x(address), 64)
].join('').toLowerCase(),
to: ensure0x(this._contractAddress).toLowerCase()
},
'latest'
))
)