我正在尝试广播pycoin库的事务。通过rpc查询获得接收方地址,通过API查询获得UTXO地址,然后创建Spendaples对象,指定要支付的硬币、费用、签署交易,最后尝试以十六进制发送原始交易。但我得到的回应是错误-25:缺少输入。网络不是比特币,而是BCS。我的硬币不花任何钱,只是示范硬币。 我怎样才能解决这个问题?提前谢谢你! 构建特定网络(BCS)和事务的代码:
from pycoin.coins.bitcoin.Tx import Spendable
from pycoin.coins.tx_utils import create_tx
from pycoin.networks.bitcoinish import create_bitcoinish_network
from pycoin.encoding.hexbytes import h2b
import json
import requests
class BCS_net():
def __init__(self, addr_sender: str, rpc_user: str, rpc_pass: str, NET_PARAMS: dict):
self.address_sender = addr_sender
self.rpc_user = rpc_user
self.rpc_pass = rpc_pass
self.network = create_bitcoinish_network(symbol = NET_PARAMS['symbol'], network_name = NET_PARAMS['network_name'],
subnet_name = NET_PARAMS['subnet_name'], wif_prefix_hex=NET_PARAMS['wif_prefix_hex'],
address_prefix_hex=NET_PARAMS['address_prefix_hex'], pay_to_script_prefix_hex=NET_PARAMS['pay_to_script_prefix_hex'],
bip32_prv_prefix_hex=NET_PARAMS['bip32_prv_prefix_hex'], bip32_pub_prefix_hex=NET_PARAMS['bip32_pub_prefix_hex'],
bech32_hrp=NET_PARAMS['bech32_hrp'], bip49_prv_prefix_hex=NET_PARAMS['bip49_prv_prefix_hex'],
bip49_pub_prefix_hex=NET_PARAMS['bip49_pub_prefix_hex'], bip84_prv_prefix_hex=NET_PARAMS['bip84_prv_prefix_hex'],
bip84_pub_prefix_hex=NET_PARAMS['bip84_pub_prefix_hex'], magic_header_hex=NET_PARAMS['magic_header_hex'], default_port=NET_PARAMS['default_port'])
def create_tx(self, satoshis:int, solver_f, generator):
utxo = self.get_utxo(self)
address_reciever = json.loads(self.send_rpc(self, 'getnewaddress').text)['result']
self.spendables = Spendable(coin_value=int(utxo['value']), script = h2b(utxo['scriptPubKey']), tx_hash = h2b(utxo['transactionId']), tx_out_index=int(utxo['outputIndex']))
self.unsigned_tx = create_tx(
network=self.network,
spendables=[self.spendables],
payables=[tuple([address_reciever, satoshis])],
fee='standard'
# fee=0
)
self.unsigned_tx_hex = self.unsigned_tx.as_hex()
key_wif = self.network.parse.wif(self.secret_key)
exponent = key_wif.secret_exponent()
solver = solver_f([exponent], [generator])
self.signed_new_tx = self.unsigned_tx.sign(solver)
self.signed_new_tx_hex = self.signed_new_tx.as_hex()
@classmethod
def get_utxo(cls ,self):
utxo = requests.get(f'https://bcschain.info/api/address/{self.address_sender}/utxo')
utxo = json.loads(utxo.text)[0]
return utxo
@classmethod
def send_rpc(cls, self, method: str, params = []):
address_reciever = requests.post(f'http://{self.rpc_user}:{self.rpc_pass}@140.82.36.227:3669/', json={'method': method})
print(address_reciever.text)
return address_reciever
测试广播代码:
from tx_creation import BCS_net
from pycoin.solve.utils import build_hash160_lookup, build_p2sh_lookup, build_sec_lookup
from pycoin.ecdsa.secp256k1 import secp256k1_generator
from bitcoinrpc.authproxy import AuthServiceProxy
import sys
import json
from conf import NET_PARAMS
# method = 'getnewaddress'
# method_send = 'sendrawtransaction'
addr_to_spend = 'BM3WwFWYvz7TdvvEp9EGUB6mSg2jiM5fW6'
Bcs_network = BCS_net(addr_to_spend, rpc_user = 'bcs_tester', rpc_pass='iLoveBCS', NET_PARAMS=NET_PARAMS)
Bcs_network.create_tx(satoshis = 1000000, solver_f = build_hash160_lookup, generator = secp256k1_generator)
conn = AuthServiceProxy('http://bcs_tester:iLoveBCS@140.82.36.227:3669/')
decoded_tx = conn.decoderawtransaction(Bcs_network.signed_new_tx_hex)
# !!!bitcoinrpc.authproxy.JSONRPCException: -25: Missing inputs
print(conn.sendrawtransaction(Bcs_network.signed_new_tx_hex))
url = 'https://bcschain.info/api/tx/send'
目前没有回答
相关问题 更多 >
编程相关推荐