def create_block(self, node, vtx=[]):
    bt = node.getblocktemplate()
    height = bt['height']
    tip_hash = bt['previousblockhash']
    coinbasevalue = bt['coinbasevalue']
    miner_address = node.getnewaddress()
    mn_payee = bt['masternode'][0]['payee']
    bt_fees = 0
    for tx in bt['transactions']:
        bt_fees += tx['fee']
    new_fees = 0
    for tx in vtx:
        in_value = 0
        out_value = 0
        for txin in tx.vin:
            txout = node.gettxout(('%064x' % txin.prevout.hash), txin.prevout.n, False)
            in_value += int((txout['value'] * COIN))
        for txout in tx.vout:
            out_value += txout.nValue
        new_fees += (in_value - out_value)
    coinbasevalue -= bt_fees
    coinbasevalue += new_fees
    mn_amount = get_masternode_payment(height, coinbasevalue)
    miner_amount = (coinbasevalue - mn_amount)
    outputs = {miner_address: str((Decimal(miner_amount) / COIN))}
    if (mn_amount > 0):
        outputs[mn_payee] = str((Decimal(mn_amount) / COIN))
    coinbase = FromHex(CTransaction(), node.createrawtransaction([], outputs))
    coinbase.vin = create_coinbase(height).vin
    if (len(bt['coinbase_payload']) != 0):
        cbtx = FromHex(CCbTx(version=1), bt['coinbase_payload'])
        coinbase.nVersion = 3
        coinbase.nType = 5
        coinbase.vExtraPayload = cbtx.serialize()
    coinbase.calc_sha256()
    block = create_block(int(tip_hash, 16), coinbase, nTime=bt['curtime'])
    block.vtx += vtx
    for tx in bt['transactions']:
        tx2 = FromHex(CTransaction(), tx['data'])
        if (tx2.nType == 6):
            block.vtx.append(tx2)
    block.hashMerkleRoot = block.calc_merkle_root()
    block.solve()
    return block
def create_block(self, node, vtx=[]):
    bt = node.getblocktemplate()
    height = bt['height']
    tip_hash = bt['previousblockhash']
    coinbasevalue = bt['coinbasevalue']
    miner_address = node.getnewaddress()
    mn_payee = bt['masternode'][0]['payee']
    bt_fees = 0
    for tx in bt['transactions']:
        bt_fees += tx['fee']
    new_fees = 0
    for tx in vtx:
        in_value = 0
        out_value = 0
        for txin in tx.vin:
            txout = node.gettxout(('%064x' % txin.prevout.hash), txin.prevout.n, False)
            in_value += int((txout['value'] * COIN))
        for txout in tx.vout:
            out_value += txout.nValue
        new_fees += (in_value - out_value)
    coinbasevalue -= bt_fees
    coinbasevalue += new_fees
    mn_amount = get_masternode_payment(height, coinbasevalue)
    miner_amount = (coinbasevalue - mn_amount)
    outputs = {miner_address: str((Decimal(miner_amount) / COIN))}
    if (mn_amount > 0):
        outputs[mn_payee] = str((Decimal(mn_amount) / COIN))
    coinbase = FromHex(CTransaction(), node.createrawtransaction([], outputs))
    coinbase.vin = create_coinbase(height).vin
    if (len(bt['coinbase_payload']) != 0):
        cbtx = FromHex(CCbTx(version=1), bt['coinbase_payload'])
        coinbase.nVersion = 3
        coinbase.nType = 5
        coinbase.vExtraPayload = cbtx.serialize()
    coinbase.calc_sha256()
    block = create_block(int(tip_hash, 16), coinbase, nTime=bt['curtime'])
    block.vtx += vtx
    for tx in bt['transactions']:
        tx2 = FromHex(CTransaction(), tx['data'])
        if (tx2.nType == 6):
            block.vtx.append(tx2)
    block.hashMerkleRoot = block.calc_merkle_root()
    block.solve()
    return block