use a fanout tx to create inputs
This commit is contained in:
@@ -4,42 +4,14 @@ import json
|
|||||||
from testsupport import *
|
from testsupport import *
|
||||||
|
|
||||||
|
|
||||||
def wait_for_block(height):
|
|
||||||
for i in range(100):
|
|
||||||
try:
|
|
||||||
return rpc.getblock(str(height))
|
|
||||||
except RPCError as e:
|
|
||||||
time.sleep(3)
|
|
||||||
raise Exception('Time out waiting for block at height %s' % height)
|
|
||||||
|
|
||||||
|
|
||||||
def sign_and_submit(tx):
|
|
||||||
signed = hoek.signTxBitcoin({'tx': tx, 'privateKeys': [notary_sk]})
|
|
||||||
signed = hoek.signTxEd25519({'tx': signed['tx'], 'privateKeys': [alice_sk]})
|
|
||||||
encoded = hoek.encodeTx(signed)
|
|
||||||
try:
|
|
||||||
rpc.getrawtransaction(encoded['txid'])
|
|
||||||
return encoded['txid']
|
|
||||||
except RPCError:
|
|
||||||
pass
|
|
||||||
print >> sys.stderr, "submit transaction: %s:%s" % (encoded['txid'], json.dumps(signed))
|
|
||||||
return rpc.sendrawtransaction(encoded['hex'])
|
|
||||||
|
|
||||||
|
|
||||||
def test_basic_spend():
|
def test_basic_spend():
|
||||||
block = wait_for_block(3)
|
|
||||||
reward_txid = block['tx'][0]
|
|
||||||
reward_tx_raw = rpc.getrawtransaction(reward_txid)
|
|
||||||
reward_tx = hoek.decodeTx({'hex': reward_tx_raw})
|
|
||||||
balance = reward_tx['tx']['outputs'][0]['amount']
|
|
||||||
|
|
||||||
spend0 = {
|
spend0 = {
|
||||||
'inputs': [
|
'inputs': [
|
||||||
{'txid': reward_txid, 'idx': 0, 'script': {'pubkey': notary_pk}}
|
{'txid': fanout, 'idx': 0, 'script': {'address': notary_addr}}
|
||||||
],
|
],
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{"amount": 1000, "script": {"condition": cond_alice}},
|
{"amount": 500, "script": {"condition": cond_alice}},
|
||||||
{"amount": balance - 1000, "script": {"address": notary_addr}}
|
{"amount": 500, "script": {"address": notary_addr}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +23,7 @@ def test_basic_spend():
|
|||||||
{'txid': spend0_txid, 'idx': 1, 'script': {'address': notary_addr}}
|
{'txid': spend0_txid, 'idx': 1, 'script': {'address': notary_addr}}
|
||||||
],
|
],
|
||||||
'outputs': [
|
'outputs': [
|
||||||
{"amount": balance, "script": {"address": notary_addr}}
|
{"amount": 1000, "script": {"address": notary_addr}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,17 +34,7 @@ def test_basic_spend():
|
|||||||
print("all done!")
|
print("all done!")
|
||||||
|
|
||||||
|
|
||||||
notary_addr = 'RXSwmXKtDURwXP7sdqNfsJ6Ga8RaxTchxE'
|
|
||||||
notary_pk = '0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47'
|
|
||||||
notary_sk = 'UxFWWxsf1d7w7K5TvAWSkeX4H95XQKwdwGv49DXwWUTzPTTjHBbU'
|
|
||||||
alice_pk = '8ryTLBMnozUK4xUz7y49fjzZhxDDMK7c4mucLdbVY6jW'
|
|
||||||
alice_sk = 'E4ER7uYvaSTdpQFzTXNNSTkR6jNRJyqhZPJMGuU899nY'
|
|
||||||
cond_alice = {"type": "ed25519-sha-256", "publicKey": alice_pk}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
hoek = Hoek()
|
fanout = setup()
|
||||||
rpc = Komodod('/home/scott/.komodo/CCWAT/CCWAT.conf')
|
|
||||||
test_basic_spend()
|
test_basic_spend()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
@@ -31,17 +33,92 @@ def run_cmd(cmd):
|
|||||||
|
|
||||||
class Hoek(JsonClient):
|
class Hoek(JsonClient):
|
||||||
def _exec(self, method, args):
|
def _exec(self, method, args):
|
||||||
return self.load_response(run_cmd(['hoek', method, json.dumps(args[0])]))
|
cmd = ['hoek', method, json.dumps(args[0])]
|
||||||
|
return self.load_response(run_cmd(cmd))
|
||||||
|
|
||||||
|
|
||||||
class Komodod(JsonClient):
|
class Komodod(JsonClient):
|
||||||
def __init__(self, conf_path):
|
|
||||||
urltpl = 'http://$rpcuser:$rpcpassword@${rpchost:-127.0.0.1}:$rpcport'
|
|
||||||
cmd = ['bash', '-c', '. "%s"; echo -n %s' % (conf_path, urltpl)]
|
|
||||||
self.url = run_cmd(cmd)
|
|
||||||
|
|
||||||
def _exec(self, method, args):
|
def _exec(self, method, args):
|
||||||
req = {'method': method, 'params': args, 'id': 1}
|
req = {'method': method, 'params': args, 'id': 1}
|
||||||
cmd = ['curl', '-s', '-H', 'Content-Type: application/json', '-d', json.dumps(req), self.url]
|
cmd = ['curl', '-s', '-H', 'Content-Type: application/json',
|
||||||
|
'-d', json.dumps(req), CONFIG['komodod_url']]
|
||||||
return self.load_response(run_cmd(cmd))
|
return self.load_response(run_cmd(cmd))
|
||||||
|
|
||||||
|
|
||||||
|
rpc = Komodod()
|
||||||
|
hoek = Hoek()
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_block(height):
|
||||||
|
print >>sys.stderr, "Waiting for block height %s" % height
|
||||||
|
for i in range(100):
|
||||||
|
try:
|
||||||
|
return rpc.getblock(str(height))
|
||||||
|
except RPCError as e:
|
||||||
|
time.sleep(3)
|
||||||
|
raise Exception('Time out waiting for block at height %s' % height)
|
||||||
|
|
||||||
|
|
||||||
|
def sign_and_submit(tx):
|
||||||
|
signed = hoek.signTxBitcoin({'tx': tx, 'privateKeys': [notary_sk]})
|
||||||
|
signed = hoek.signTxEd25519({'tx': signed['tx'], 'privateKeys': [alice_sk]})
|
||||||
|
encoded = hoek.encodeTx(signed)
|
||||||
|
try:
|
||||||
|
rpc.getrawtransaction(encoded['txid'])
|
||||||
|
print >> sys.stderr, "Transaction already in chain: %s" % encoded['txid']
|
||||||
|
return encoded['txid']
|
||||||
|
except RPCError:
|
||||||
|
pass
|
||||||
|
print >> sys.stderr, "submit transaction: %s:%s" % (encoded['txid'], json.dumps(signed))
|
||||||
|
print encoded
|
||||||
|
return rpc.sendrawtransaction(encoded['hex'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG = None
|
||||||
|
FANOUT_TXID = None
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
global CONFIG, FANOUT_TXID
|
||||||
|
if not CONFIG:
|
||||||
|
parser = argparse.ArgumentParser(description='Crypto-Condition integration suite.')
|
||||||
|
parser.add_argument('komodod_conf', help='Location of Komodod config file')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
urltpl = 'http://$rpcuser:$rpcpassword@${rpchost:-127.0.0.1}:$rpcport'
|
||||||
|
cmd = ['bash', '-c', '. %s && echo -n %s' % (args.komodod_conf, urltpl)]
|
||||||
|
url = run_cmd(cmd)
|
||||||
|
|
||||||
|
CONFIG = {'komodod_url': url}
|
||||||
|
|
||||||
|
if not FANOUT_TXID:
|
||||||
|
block = wait_for_block(1)
|
||||||
|
reward_txid = block['tx'][0]
|
||||||
|
reward_tx_raw = rpc.getrawtransaction(reward_txid)
|
||||||
|
reward_tx = hoek.decodeTx({'hex': reward_tx_raw})
|
||||||
|
balance = reward_tx['tx']['outputs'][0]['amount']
|
||||||
|
|
||||||
|
n_outs = 100
|
||||||
|
remainder = balance - n_outs * 1000
|
||||||
|
|
||||||
|
fanout = {
|
||||||
|
'inputs': [
|
||||||
|
{'txid': reward_txid, 'idx': 0, 'script': {'pubkey': notary_pk}}
|
||||||
|
],
|
||||||
|
"outputs": (100 * [
|
||||||
|
{"amount": 1000, "script": {"address": notary_addr}}
|
||||||
|
] + [{"amount": remainder, 'script': {'address': notary_addr}}])
|
||||||
|
}
|
||||||
|
|
||||||
|
FANOUT_TXID = sign_and_submit(fanout)
|
||||||
|
|
||||||
|
return FANOUT_TXID
|
||||||
|
|
||||||
|
|
||||||
|
notary_addr = 'RXSwmXKtDURwXP7sdqNfsJ6Ga8RaxTchxE'
|
||||||
|
notary_pk = '0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47'
|
||||||
|
notary_sk = 'UxFWWxsf1d7w7K5TvAWSkeX4H95XQKwdwGv49DXwWUTzPTTjHBbU'
|
||||||
|
alice_pk = '8ryTLBMnozUK4xUz7y49fjzZhxDDMK7c4mucLdbVY6jW'
|
||||||
|
alice_sk = 'E4ER7uYvaSTdpQFzTXNNSTkR6jNRJyqhZPJMGuU899nY'
|
||||||
|
cond_alice = {"type": "ed25519-sha-256", "publicKey": alice_pk}
|
||||||
|
|||||||
Reference in New Issue
Block a user