Exemplo n.º 1
0
    def process(rpcconn,from_addr,to_addr,amount):
        # utxos
        all = BTC_ListUTXO.utxo(rpcconn,from_addr)
        # recommend
        from utils import recommended
        selected,aggregate = recommended(all,amount)
        # check if enough
        from utils import calcFee

        if not isinstance(amount, Decimal):
            amount = Decimal(str(amount))
        fee = calcFee(len(selected))
        if aggregate < fee + amount:
            return False,"budget not enough"
        # make augmentations
        from utils import filtered
        param_in = [filtered(item,["txid","vout"]) for item in selected]
        param_out = {to_addr:amount,from_addr:aggregate-amount-fee}
        print("--------------param_out-------------")
        print("fee" + str(fee))
        print(param_in)
        print(param_out)
        print("--------------param_out-------------")
        # create raw transaction
        commands = [["createrawtransaction",param_in,param_out]]
        return True, {"hex":rpcconn.batch_(commands),"utxos":selected, "txout":param_out}
Exemplo n.º 2
0
 def calcprevtx(rpc_connection,addr,amount):
     # utxos
     all = BTC_ListUTXO.utxo(rpc_connection,addr)
     # recommend
     from utils import recommended
     selected,aggregate = recommended(all,amount)
     # make augmentations
     from utils import filtered
     return [filtered(item,["txid","vout","amount","redeemScript","scriptPubKey"]) for item in selected]
Exemplo n.º 3
0
 def genearateInParam(rpcconn,src,dest):
     utxos,gross,amount = [],Decimal('0'),sum(dest.values())
     for addr in src:
         # utxos
         all = BTC_ListUTXO.utxo(rpcconn,addr)
         # recommend
         from utils import recommended
         selected,aggregate = recommended(all,amount)
         # process
         utxos += selected
         gross += aggregate
         # check if enough
         from utils import calcFee
         redundant = gross - calcFee(len(utxos),len(dest.keys())+1) - amount
         if redundant > 0:
             return True,utxos,redundant
     return False,utxos,redundant
Exemplo n.º 4
0
 def post(self):
     omni_rpc_connection = AuthServiceProxy(OMNI_RPC_URL)#todo-junying-20190313
     try:
         # get arguments
         from_addr = self.get_argument("from") if self.get_argument("from") else 'mtwEVo8FVJrMcms1GyzhbTUSafwDKvyjsq'
         to_addr = self.get_argument("to") if self.get_argument("to") else 'mzkUX6sZ3bSqK7wk8sZmrR7wUwY3QJQVaE'
         amount = self.get_argument("amount")
         fee = Decimal(self.get_argument("fee")) if self.get_argument("fee") else Decimal(OMNI_TRANSACTION_FEE)
         # utxos
         from btc.handler import BTC_ListUTXO
         all = BTC_ListUTXO.utxo(omni_rpc_connection,from_addr)
         # recommend
         from utils import recommended
         selected,aggregate = recommended(all,fee)
         # check if enough
         from utils import calcFee
         fee_ = max(fee,calcFee(len(selected)))
         if aggregate < fee_:
             self.write(json.dumps(BaseHandler.error_ret_with_data("budget not enough")))
             return
         # omni_createpayload_simplesend
         rawdata1 = OMNI_CreateRawTransaction.omni_createpayload_simplesend(omni_rpc_connection,amount)
         # createrawtransaction
         from utils import filtered
         # deletekey(selected,u'vout'); addkey(selected,u'vout',1)
         param_in = [filtered(item,["txid","vout"]) for item in selected]
         param_out = {from_addr:aggregate - fee_}
         rawdata2 = OMNI_CreateRawTransaction.createrawtransaction(omni_rpc_connection,param_in,param_out)
         # omni_createrawtx_opreturn
         rawdata3 = OMNI_CreateRawTransaction.omni_createrawtx_opreturn(omni_rpc_connection,rawdata2,rawdata1)
         # omni_createrawtx_reference
         rawdata4 = OMNI_CreateRawTransaction.omni_createrawtx_reference(omni_rpc_connection,rawdata3,to_addr)
         # omni_createrawtx_change
         param_in = [filtered(item,["txid","vout","scriptPubKey","amount"]) for item in selected]
         from utils import distribute
         param_in = distribute(param_in,'amount','value',aggregate - fee_)
         rawhex = OMNI_CreateRawTransaction.omni_createrawtx_change(omni_rpc_connection,rawdata4,param_in,from_addr,fee_)
         # return
         self.write(json.dumps(BaseHandler.success_ret_with_data({"hex":rawhex,"utxos":selected}), default=decimal_default))
     except Exception as e:
         self.write(json.dumps(BaseHandler.error_ret_with_data("error: %s"%e)))
         print("OMNI_CreateRawTransaction error:{0} in {1}".format(e,get_linenumber()))