<commit_before>var keystore = require('./keystore.js')
var txutils = require('./txutils.js')

function _setTxData (blockchainApi, fromAddr, txObject) {

    var txObjectCopy = {}

    if (txObject.nonce === undefined) {
        txObjectCopy.nonce = blockchainApi.getNonce(fromAddr)
    }
    else {
        txObjectCopy.nonce = txObject.nonce
    }

    if (txObject.gasPrice === undefined) {
        txObjectCopy.gasPrice = 10000000000000
    }
    else {
        txObjectCopy.gasPrice = txObject.gasPrice
    }

    if (txObject.gasLimit === undefined) {
        // Use the highest gaslimit that can be afforded
        var balance = blockchainApi.getBalance(fromAddr)
        var gasLimit = balance / txObjectCopy.gasPrice

        txObjectCopy.gasLimit = Math.min(3000000, gasLimit)
    }
    else {
        txObjectCopy.gasLimit = txObject.gasLimit
    }

    txObjectCopy.value = txObject.value

    return txObjectCopy
}

function sendFunctionTx (abi, contractAddr, functionName, args, fromAddr, txData, blockchainApi, keystore, password) {
    // txData contains optional values gasPrice, gasLimit, nonce, value

    var txObjectCopy = _setTxData(blockchainApi, fromAddr, txData)
    txObjectCopy.to = contractAddr
    var tx = txutils.functionTx(abi, functionName, args, txObjectCopy)
    var signedTx = keystore.signTx(tx, password, fromAddr)

    return blockchainApi.injectTransaction(signedTx)
}

function sendCreateContractTx (bytecode, fromAddr, txData, blockchainApi, keystore, password) {
    // txData contains optional values gasPrice, gasLimit, nonce, value

    var txObjectCopy = _setTxData(blockchainApi, fromAddr, txData)
    txObjectCopy.data = bytecode
    var out = txutils.createContractTx(fromAddr, txObjectCopy)
    var signedTx = keystore.signTx(out.tx, password, fromAddr)

    return blockchainApi.injectTransaction(signedTx)
}

function sendValueTx (fromAddr, value, txData, blockchainApi, keystore, password) {
    // txData contains optional values gasPrice, gasLimit, nonce

    var txObjectCopy = _setTxData(blockchainApi, fromAddr, txData)
    txObjectCopy.value = value
    var tx = txutils.valueTx(txObjectCopy)
    var signedTx = keystore.signTx(tx, password, fromAddr)

    return blockchainApi.injectTransaction(signedTx)
}

module.exports = {
  _setTxData: _setTxData,
  sendFunctionTx: sendFunctionTx,
  sendCreateContractTx: sendCreateContractTx,
  sendValueTx: sendValueTx
}<commit_msg>Injecting transactions will not return the address when creating contracts.<commit_after>var keystore = require('./keystore.js')
var txutils = require('./txutils.js')

function _setTxData (blockchainApi, fromAddr, txObject) {

    var txObjectCopy = {}

    if (txObject.nonce === undefined) {
        txObjectCopy.nonce = blockchainApi.getNonce(fromAddr)
    }
    else {
        txObjectCopy.nonce = txObject.nonce
    }

    if (txObject.gasPrice === undefined) {
        txObjectCopy.gasPrice = 10000000000000
    }
    else {
        txObjectCopy.gasPrice = txObject.gasPrice
    }

    if (txObject.gasLimit === undefined) {
        // Use the highest gaslimit that can be afforded
        var balance = blockchainApi.getBalance(fromAddr)
        var gasLimit = balance / txObjectCopy.gasPrice

        txObjectCopy.gasLimit = Math.min(3000000, gasLimit)
    }
    else {
        txObjectCopy.gasLimit = txObject.gasLimit
    }

    txObjectCopy.value = txObject.value

    return txObjectCopy
}

function sendFunctionTx (abi, contractAddr, functionName, args, fromAddr, txData, blockchainApi, keystore, password) {
    // txData contains optional values gasPrice, gasLimit, nonce, value

    var txObjectCopy = _setTxData(blockchainApi, fromAddr, txData)
    txObjectCopy.to = contractAddr
    var tx = txutils.functionTx(abi, functionName, args, txObjectCopy)
    var signedTx = keystore.signTx(tx, password, fromAddr)

    return blockchainApi.injectTransaction(signedTx)
}

function sendCreateContractTx (bytecode, fromAddr, txData, blockchainApi, keystore, password) {
    // txData contains optional values gasPrice, gasLimit, nonce, value

    var txObjectCopy = _setTxData(blockchainApi, fromAddr, txData)
    txObjectCopy.data = bytecode
    var out = txutils.createContractTx(fromAddr, txObjectCopy)
    var signedTx = keystore.signTx(out.tx, password, fromAddr)

    blockchainApi.injectTransaction(signedTx)

    return out.addr
}

function sendValueTx (fromAddr, value, txData, blockchainApi, keystore, password) {
    // txData contains optional values gasPrice, gasLimit, nonce

    var txObjectCopy = _setTxData(blockchainApi, fromAddr, txData)
    txObjectCopy.value = value
    var tx = txutils.valueTx(txObjectCopy)
    var signedTx = keystore.signTx(tx, password, fromAddr)

    return blockchainApi.injectTransaction(signedTx)
}

module.exports = {
  _setTxData: _setTxData,
  sendFunctionTx: sendFunctionTx,
  sendCreateContractTx: sendCreateContractTx,
  sendValueTx: sendValueTx
}
{'fraction_non_alphanumeric': 0.08616504854368932, 'fraction_numerical': 0.00849514563106796, 'mean_word_length': 3.8291015625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2042784', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1452, 'n_words': 352}