def main() :
    parser = argparse.ArgumentParser(description='Tool to update the voter key of a coldstorage address')
    parser.add_argument('--voteaddress', type=str, help='address that will be allowed to vote with cold funds instead')
    parser.add_argument('--account', type=str, help='account that will be allowed to vote with cold funds instead')
    parser.add_argument('--rpcurl', type=str, help='')
    parser.add_argument('--rpcuser', type=str, help='')
    parser.add_argument('--rpcpasswd', type=str, help='')
    parser.add_argument('--output', type=str, help='filename into which the signed output is stored')
    parser.set_defaults(rpcurl=config.url, rpcuser=config.user, rpcpasswd=config.passwd)
    parser.set_defaults(output="signedtx.txt")
    args = parser.parse_args()
    slate_id = None

    ''' Connect to bitshares client via RPC '''
    rpc = bitsharesrpc.client(args.rpcurl, args.rpcuser, args.rpcpasswd)

    if not args.voteaddress and not args.account :
        print("No voteaddress given! Please specify!")
        args.voteaddress  = ask_for_address() 
    if args.account :
        args.voteaddress  = rpc.wallet_address_create(args.account)[ "result" ]
        print("Using %s from account %s" %(args.voteaddress, args.account))

    ''' Ask for the private key '''
    privkey  = ask_for_privkey()
    address  = Address.priv2btsaddr(Address.wif2hex(privkey))

    ''' balance ids '''
    balances = rpc.blockchain_list_address_balances(address)["result"]
    print("This address holds the following BTS funds (ignoring other assets):")
    ops      = []
    for balance in balances :
        balanceId = balance[0]
        asset_id  = balance[1]["condition"]["asset_id"]
        asset    = rpc.blockchain_get_asset(asset_id)["result"]
        if asset_id == 0 :
            if balance[1]["balance"] == 0: continue
            print("- %f BTS" % ((balance[1]["balance"])/float(asset["precision"])))
            votekeyop      = Transaction.UpdateBalanceVote(balanceId, args.voteaddress, slate_id)
            ops.append(Transaction.Operation( "update_balance_vote_op_type", votekeyop ))

    tx             = Transaction.Transaction( 60*60*12, None, ops )
    sigtx          = Transaction.SignedTransaction(tx, [privkey])

    ''' Store signed transaction '''
    with open(args.output,"wb") as fp :
        fp.write(json.dumps(sigtx.tojson()))
    print("\n%d transaction successfully signed and output written to file '%s'" % (len(ops), args.output) )
    print("To broadcast transaction copy the file and run ./broadcast_signed_tx.py on online computer")
Example #2
0
def main():
    parser = argparse.ArgumentParser(
        description='Offline tool to gather balances in cold storage address')
    parser.add_argument(
        '--coldaddress',
        type=str,
        help='cold storage address to get funds from (required)')
    parser.add_argument('--filename',
                        type=str,
                        help='filename in which to store the available funds')
    parser.add_argument('--rpcurl', type=str, help='')
    parser.add_argument('--rpcuser', type=str, help='')
    parser.add_argument('--rpcpasswd', type=str, help='')
    parser.set_defaults(rpcurl=config.url,
                        rpcuser=config.user,
                        rpcpasswd=config.passwd)
    parser.set_defaults(filename="availablefunds.txt")
    args = parser.parse_args()

    if not args.coldaddress:
        print("No voteaddress given! Please specify!")
        args.coldaddress = ask_for_address()
    ''' Connect to bitshares client via RPC '''
    rpc = bitsharesrpc.client(args.rpcurl, args.rpcuser, args.rpcpasswd)
    ''' Get available funds '''
    balances = get_available_balances(rpc, args.coldaddress)
    ''' Format for transfer '''
    print("Available Funds in cold storage address %s:" % args.coldaddress)
    funds = []
    for t in balances:
        funds.append("%f ; %s ; %d ; %d ; %s ; %s\n" %
                     (t["balance"], t["symbol"], t["asset_id"], t["precision"],
                      t["balanceid"], t["owner"]))
        print("- %f %s" % (t["balance"], t["symbol"]))

    with open(args.filename, "w") as fp:
        fp.write(str("".join(funds)))

    print(
        "Stored funds for %d assets in '%s' for offline construction & signing."
        % (len(funds), args.filename))
Example #3
0
def main():
    global PREFIX
    parser = argparse.ArgumentParser(
        description=
        'Online tool to define and sign transaction from coldstorage')
    parser.add_argument(
        '--address',
        type=str,
        help=
        'Address to send the funds to (hot address) (default: scan per QR-code)'
    )
    parser.add_argument(
        '--filename',
        type=str,
        help='File created by the online tool containing available balances')
    parser.add_argument('--txfee',
                        type=float,
                        help='txfee substracted from your funds')
    parser.add_argument('--prefix',
                        type=str,
                        help='defaults to "BTS" (advanced feature)')
    parser.add_argument('--output',
                        type=str,
                        help='filename into which the signed output is stored')
    parser.set_defaults(filename="availablefunds.txt",
                        output="signedtx.txt",
                        txfee=0.5)
    parser.set_defaults(prefix="BTS")
    args = parser.parse_args()
    PREFIX = args.prefix
    ''' If an address is given, verify validity '''
    if args.address:
        try:
            b58.btsBase58CheckDecode(args.address[len(PREFIX):])
        except:
            raise Exception("Invalid address format")
    ''' Read the balance file '''
    availableBalance = readBalanceFile(args.filename)
    ''' Ask the user to input the funds to be transfered '''
    transferbalances = input_transfer_asset_balances()
    ''' Add the TX fee in BTS '''
    transferbalances = addfee(transferbalances, args.txfee)
    ''' Check if the funds entered (plus fee) can be paid '''
    check_availability(availableBalance, transferbalances)
    ''' construct withdrawal amounts and assets '''
    withdrawSet = prepare_withdraw(availableBalance, transferbalances)
    ''' Ask for the target address if not given as parameter '''
    if not args.address:
        args.address = ask_for_address()
    ''' Construct the transaction '''
    ops = []
    for w in withdrawSet:
        amount = w[0]
        asset_id = w[2]
        balanceid = w[4]
        ''' Withdrawal from coldstorage '''
        ops.append(
            Transaction.Operation("withdraw_op_type",
                                  Transaction.Withdraw(balanceid,
                                                       int(amount))))
        ''' Deposit to hot wallet '''
        if asset_id == 0:  # substract txfee
            amount -= args.txfee * 1e5
            if not amount:
                continue
        wst = Transaction.WithdrawSignatureType(args.address)
        wc = Transaction.WithdrawCondition(asset_id, None,
                                           "withdraw_signature_type", wst)
        deposit = Transaction.Deposit(int(amount), wc)
        ops.append(Transaction.Operation("deposit_op_type", deposit))
    tx = Transaction.Transaction(60 * 60 * 12, 0, ops)

    print("Raw and unsigned transaction for verification:")
    print(json.dumps(tx.tojson(), indent=4))

    print("The following funds will be moved out of cold storage:")
    for w in withdrawSet:
        amount = w[0]
        symbol = w[1]
        precision = w[3]
        print(" - %f %s" % (amount / precision, symbol))
    print("%d Operation(s) need to be signed." % (len(ops)))
    ''' Ask for the private key '''
    privkey = ask_for_privkey(withdrawSet[0][5])
    ''' Sign transaction '''
    sigtx = Transaction.SignedTransaction(tx, [privkey])
    ''' Store signed transaction '''
    with open(args.output, "wb") as fp:
        fp.write(json.dumps(sigtx.tojson()))
    print(
        "\n%d transaction successfully signed and output written to file '%s'"
        % (len(ops), args.output))
    print(
        "To broadcast transaction copy the file and run ./online/broadcast_signed_tx.py on online computer"
    )
Example #4
0
def main() :
    global PREFIX
    parser = argparse.ArgumentParser(description='Online tool to define and sign transaction from coldstorage')
    parser.add_argument('--address', type=str, help='Address to send the funds to (hot address) (default: scan per QR-code)')
    parser.add_argument('--filename', type=str, help='File created by the online tool containing available balances')
    parser.add_argument('--txfee', type=float, help='txfee substracted from your funds')
    parser.add_argument('--prefix', type=str, help='defaults to "BTS" (advanced feature)')
    parser.add_argument('--output', type=str, help='filename into which the signed output is stored')
    parser.set_defaults(filename="availablefunds.txt", output="signedtx.txt", txfee=0.5)
    parser.set_defaults(prefix="BTS")
    args = parser.parse_args()
    PREFIX   = args.prefix

    ''' If an address is given, verify validity '''
    if args.address :
        try :
            b58.btsBase58CheckDecode(args.address[len(PREFIX):])
        except :
            raise Exception("Invalid address format")

    ''' Read the balance file '''
    availableBalance     = readBalanceFile(args.filename)

    ''' Ask the user to input the funds to be transfered '''
    transferbalances     = input_transfer_asset_balances()

    ''' Add the TX fee in BTS '''
    transferbalances     = addfee(transferbalances, args.txfee)

    ''' Check if the funds entered (plus fee) can be paid '''
    check_availability(availableBalance, transferbalances)

    ''' construct withdrawal amounts and assets '''
    withdrawSet = prepare_withdraw( availableBalance, transferbalances )

    ''' Ask for the target address if not given as parameter '''
    if not args.address :
        args.address  = ask_for_address() 

    ''' Construct the transaction '''
    ops = []
    for w in withdrawSet :
        amount    = w[0]
        asset_id  = w[2]
        balanceid = w[4]

        ''' Withdrawal from coldstorage '''
        ops.append(Transaction.Operation("withdraw_op_type", Transaction.Withdraw(balanceid, int(amount)) ))

        ''' Deposit to hot wallet '''
        if asset_id == 0 : # substract txfee
            amount -= args.txfee * 1e5
            if not amount :
                continue
        wst      = Transaction.WithdrawSignatureType( args.address )
        wc       = Transaction.WithdrawCondition( asset_id, None, "withdraw_signature_type", wst)
        deposit  = Transaction.Deposit(int(amount), wc )
        ops.append(Transaction.Operation( "deposit_op_type", deposit))
    tx       = Transaction.Transaction( 60*60*12, 0, ops )

    print("Raw and unsigned transaction for verification:")
    print(json.dumps( tx.tojson(  ), indent=4 ) )

    print("The following funds will be moved out of cold storage:")
    for w in withdrawSet :
        amount    = w[0]
        symbol    = w[1]
        precision = w[3]
        print(" - %f %s" %(amount/precision, symbol))
    print("%d Operation(s) need to be signed." % (len(ops)) )

    ''' Ask for the private key '''
    privkey  = ask_for_privkey(withdrawSet[0][5])

    ''' Sign transaction '''
    sigtx    = Transaction.SignedTransaction(tx, [privkey])

    ''' Store signed transaction '''
    with open(args.output,"wb") as fp :
        fp.write(json.dumps(sigtx.tojson()))
    print("\n%d transaction successfully signed and output written to file '%s'" % (len(ops), args.output) )
    print("To broadcast transaction copy the file and run ./online/broadcast_signed_tx.py on online computer")
def main():
    parser = argparse.ArgumentParser(
        description='Tool to update the voter key of a coldstorage address')
    parser.add_argument(
        '--voteaddress',
        type=str,
        help='address that will be allowed to vote with cold funds instead')
    parser.add_argument(
        '--account',
        type=str,
        help='account that will be allowed to vote with cold funds instead')
    parser.add_argument('--rpcurl', type=str, help='')
    parser.add_argument('--rpcuser', type=str, help='')
    parser.add_argument('--rpcpasswd', type=str, help='')
    parser.add_argument('--output',
                        type=str,
                        help='filename into which the signed output is stored')
    parser.set_defaults(rpcurl=config.url,
                        rpcuser=config.user,
                        rpcpasswd=config.passwd)
    parser.set_defaults(output="signedtx.txt")
    args = parser.parse_args()
    slate_id = None
    ''' Connect to bitshares client via RPC '''
    rpc = bitsharesrpc.client(args.rpcurl, args.rpcuser, args.rpcpasswd)

    if not args.voteaddress and not args.account:
        print("No voteaddress given! Please specify!")
        args.voteaddress = ask_for_address()
    if args.account:
        args.voteaddress = rpc.wallet_address_create(args.account)["result"]
        print("Using %s from account %s" % (args.voteaddress, args.account))
    ''' Ask for the private key '''
    privkey = ask_for_privkey()
    address = Address.priv2btsaddr(Address.wif2hex(privkey))
    ''' balance ids '''
    balances = rpc.blockchain_list_address_balances(address)["result"]
    print(
        "This address holds the following BTS funds (ignoring other assets):")
    ops = []
    for balance in balances:
        balanceId = balance[0]
        asset_id = balance[1]["condition"]["asset_id"]
        asset = rpc.blockchain_get_asset(asset_id)["result"]
        if asset_id == 0:
            if balance[1]["balance"] == 0: continue
            print("- %f BTS" %
                  ((balance[1]["balance"]) / float(asset["precision"])))
            votekeyop = Transaction.UpdateBalanceVote(balanceId,
                                                      args.voteaddress,
                                                      slate_id)
            ops.append(
                Transaction.Operation("update_balance_vote_op_type",
                                      votekeyop))

    tx = Transaction.Transaction(60 * 60 * 12, None, ops)
    sigtx = Transaction.SignedTransaction(tx, [privkey])
    ''' Store signed transaction '''
    with open(args.output, "wb") as fp:
        fp.write(json.dumps(sigtx.tojson()))
    print(
        "\n%d transaction successfully signed and output written to file '%s'"
        % (len(ops), args.output))
    print(
        "To broadcast transaction copy the file and run ./broadcast_signed_tx.py on online computer"
    )