GOSTCoin Web Wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

from django.conf import settings
from bitcoinrpc.authproxy import AuthServiceProxy
def select_inputs(conn, amount):
"""Select unspent inputs to craft tx"""
unspent_inputs = conn.listunspent(0)
unspent_inputs.sort(key=lambda u: u['amount'] * u['confirmations'],
inputs, total = [], 0
for usin in unspent_inputs:
total += usin["amount"]
if total >= amount: break
if total < amount:
raise GostCoinException("Not enough coins on the server")
return inputs, total
def create_raw_tx(conn, address, amount):
"""Prepare raw transaction and return with output amount"""
# TODO calculate fee per kB
output_amount = amount + settings.GST_NETWORK_FEE
inputs, total = select_inputs(conn, output_amount)
change_amount = total - output_amount
outputs = {address: amount}
if change_amount > settings.GST_DUST:
outputs[settings.GST_CHANGE_ADDRESS] = change_amount
return conn.createrawtransaction(inputs, outputs)
class GostCoinException(Exception):
Raised when something is wrong with account balance