Skip to content

Commit

Permalink
Merge pull request #139 from ElementsProject/CA-final
Browse files Browse the repository at this point in the history
Confidential Assets support
  • Loading branch information
instagibbs committed Apr 3, 2017
2 parents 627dfeb + e27b3cc commit fd3447f
Show file tree
Hide file tree
Showing 175 changed files with 13,716 additions and 2,319 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -1120,7 +1120,7 @@ if test x$need_bundled_univalue = xyes; then
AC_CONFIG_SUBDIRS([src/univalue])
fi

ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-recovery --enable-module-schnorr --enable-module-ecdh --enable-module-rangeproof"
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-recovery --enable-module-ecdh --enable-module-rangeproof --enable-module-generator --enable-module-surjectionproof"
AC_CONFIG_SUBDIRS([src/secp256k1])

AC_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion contrib/bitcoin-cli.bash-completion
Expand Up @@ -100,7 +100,7 @@ _bitcoin_cli() {
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
return 0
;;
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendfrom|sendmany)
getaccountaddress|getaddressesbyaccount|getbalance|getnewaddress|getreceivedbyaccount|listtransactions|move|sendmany)
_bitcoin_accounts
return 0
;;
Expand Down
216 changes: 188 additions & 28 deletions qa/rpc-tests/confidential_transactions.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions qa/rpc-tests/rawtransactions.py
Expand Up @@ -81,18 +81,18 @@ def run_test(self):
mSigObjValid = self.nodes[2].validateaddress(mSigObj)

#use balance deltas instead of absolute values
bal = self.nodes[2].getbalance()
bal = self.nodes[2].getbalance()["bitcoin"]

# send 1.2 BTC to msig adr
txId = self.nodes[0].sendtoaddress(mSigObj, 1.2)
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
assert_equal(self.nodes[2].getbalance(), bal+Decimal('1.20000000')) #node2 has both keys of the 2of2 ms addr., tx should affect the balance
assert_equal(self.nodes[2].getbalance()["bitcoin"], bal+Decimal('1.20000000')) #node2 has both keys of the 2of2 ms addr., tx should affect the balance


# 2of3 test from different nodes
bal = self.nodes[2].getbalance()
bal = self.nodes[2].getbalance()["bitcoin"]
addr1 = self.nodes[1].getnewaddress()
addr2 = self.nodes[2].getnewaddress()
addr3 = self.nodes[2].getnewaddress()
Expand All @@ -114,7 +114,7 @@ def run_test(self):

#THIS IS A INCOMPLETE FEATURE
#NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
assert_equal(self.nodes[2].getbalance(), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable
assert_equal(self.nodes[2].getbalance()["bitcoin"], bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable

txDetails = self.nodes[0].gettransaction(txId, True)
rawTx = self.nodes[0].decoderawtransaction(txDetails['hex'])
Expand Down
6 changes: 3 additions & 3 deletions qa/rpc-tests/receivedby.py
Expand Up @@ -82,19 +82,19 @@ def run_test(self):
self.sync_all()

#Check balance is 0 because of 0 confirmations
balance = self.nodes[1].getreceivedbyaddress(unblinded)
balance = self.nodes[1].getreceivedbyaddress(unblinded, 1, "bitcoin")
if balance != Decimal("0.0"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))

#Check balance is 0.1
balance = self.nodes[1].getreceivedbyaddress(unblinded,0)
balance = self.nodes[1].getreceivedbyaddress(unblinded,0, "bitcoin")
if balance != Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))

#Bury Tx under 10 block so it will be returned by the default getreceivedbyaddress
self.nodes[1].generate(10)
self.sync_all()
balance = self.nodes[1].getreceivedbyaddress(unblinded)
balance = self.nodes[1].getreceivedbyaddress(unblinded, 1, "bitcoin")
if balance != Decimal("0.1"):
raise AssertionError("Wrong balance returned by getreceivedbyaddress, %0.2f"%(balance))

Expand Down
5 changes: 0 additions & 5 deletions qa/rpc-tests/test_framework/mininode.py
Expand Up @@ -475,7 +475,6 @@ class CTransaction(object):
def __init__(self, tx=None):
if tx is None:
self.nVersion = 1
self.nTxFee = 0
self.vin = []
self.vout = []
self.wit = CTxWitness()
Expand All @@ -484,7 +483,6 @@ def __init__(self, tx=None):
self.hash = None
else:
self.nVersion = tx.nVersion
self.nTxFee = tx.nTxFee
self.vin = copy.deepcopy(tx.vin)
self.vout = copy.deepcopy(tx.vout)
self.nLockTime = tx.nLockTime
Expand All @@ -494,7 +492,6 @@ def __init__(self, tx=None):

def deserialize(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0]
self.nTxFee = struct.unpack("<q", f.read(8))[0]
self.vin = deser_vector(f, CTxIn)
self.vout = deser_vector(f, CTxOut)
self.nLockTime = struct.unpack("<I", f.read(4))[0]
Expand All @@ -503,7 +500,6 @@ def deserialize(self, f):

def deserialize_with_witness(self, f):
self.nVersion = struct.unpack("<i", f.read(4))[0]
self.nTxFee = struct.unpack("<q", f.read(8))[0]
self.vin = deser_vector(f, CTxIn)
flags = 0
if len(self.vin) == 0:
Expand Down Expand Up @@ -571,7 +567,6 @@ def serialize_with_witness(self):
flags |= 2
r = b""
r += struct.pack("<i", self.nVersion)
r += struct.pack("<q", self.nTxFee)
if flags:
dummy = []
r += ser_vector(dummy)
Expand Down
8 changes: 4 additions & 4 deletions qa/rpc-tests/txn_clone.py
Expand Up @@ -37,11 +37,11 @@ def run_test(self):
self.nodes[0].settxfee(.001)

node0_address_foo = self.nodes[0].getnewaddress("foo")
fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 1219)
# fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 1219)
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid)

node0_address_bar = self.nodes[0].getnewaddress("bar")
fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 29)
# fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 29)
fund_bar_tx = self.nodes[0].gettransaction(fund_bar_txid)

assert_equal(self.nodes[0].getbalance(""),
Expand All @@ -51,8 +51,8 @@ def run_test(self):
node1_address = self.nodes[1].getnewaddress("from0")

# Send tx1, and another transaction tx2 that won't be cloned
txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0)
txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0)
# txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0)
# txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0)

# Construct a clone of tx1, to be malleated
rawtx1 = self.nodes[0].getrawtransaction(txid1,1)
Expand Down
8 changes: 4 additions & 4 deletions qa/rpc-tests/txn_doublespend.py
Expand Up @@ -35,11 +35,11 @@ def run_test(self):

# Assign coins to foo and bar accounts:
node0_address_foo = self.nodes[0].getnewaddress("foo")
fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 1219)
# fund_foo_txid = self.nodes[0].sendfrom("", node0_address_foo, 1219)
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid)

node0_address_bar = self.nodes[0].getnewaddress("bar")
fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 29)
# fund_bar_txid = self.nodes[0].sendfrom("", node0_address_bar, 29)
fund_bar_tx = self.nodes[0].gettransaction(fund_bar_txid)

assert_equal(self.nodes[0].getbalance(""),
Expand Down Expand Up @@ -67,8 +67,8 @@ def run_test(self):
assert_equal(doublespend["complete"], True)

# Create two spends using 1 50 BTC coin each
txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0)
txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0)
# txid1 = self.nodes[0].sendfrom("foo", node1_address, 40, 0)
# txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0)

# Have node0 mine a block:
if (self.options.mine_block):
Expand Down
58 changes: 29 additions & 29 deletions qa/rpc-tests/wallet.py
Expand Up @@ -29,7 +29,6 @@ def setup_network(self, split=False):
self.sync_all()

def run_test (self):
return #TODO

# Check that there's no UTXO on none of the nodes
assert_equal(len(self.nodes[0].listunspent()), 0)
Expand All @@ -39,54 +38,53 @@ def run_test (self):
print("Mining blocks...")

self.nodes[0].generate(1)

walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo['immature_balance'], 21000000)
assert_equal(walletinfo['balance'], 0)
assert_equal(walletinfo['immature_balance']["bitcoin"], 21000000)
assert("bitcoin" not in walletinfo['balance'])

self.sync_all()
self.nodes[1].generate(101)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 21000000)
assert_equal(self.nodes[1].getbalance(), 21000000)
assert_equal(self.nodes[2].getbalance(), 21000000)
assert_equal(self.nodes[0].getbalance("", 0, False, "bitcoin"), 21000000)
assert_equal(self.nodes[1].getbalance("", 0, False, "bitcoin"), 21000000)
assert_equal(self.nodes[2].getbalance("", 0, False, "bitcoin"), 21000000)

#Set all OP_TRUE genesis outputs to single node
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 21000000, "", "", True)
self.nodes[0].generate(101)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 21000000)
assert_equal(self.nodes[1].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 0)
assert_equal(self.nodes[0].getbalance("", 0, False, "bitcoin"), 21000000)
assert_equal(self.nodes[1].getbalance("", 0, False, "bitcoin"), 0)
assert_equal(self.nodes[2].getbalance("", 0, False, "bitcoin"), 0)

self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1000000)
self.nodes[0].generate(1)
self.sync_all()
#self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1000000)
#self.nodes[0].generate(1)
#self.sync_all()

self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 100000)
self.nodes[0].generate(101)
self.sync_all()
#self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 100000)
#self.nodes[0].generate(101)
#self.sync_all()

assert_equal(self.nodes[0].getbalance(), 21000000-1100000)
assert_equal(self.nodes[1].getbalance(), 1000000)
assert_equal(self.nodes[2].getbalance(), 100000)
#assert_equal(self.nodes[0].getbalance(), 21000000-1100000)
#assert_equal(self.nodes[1].getbalance(), 1000000)
#assert_equal(self.nodes[2].getbalance(), 100000)


# Send 21 BTC from 0 to 2 using sendtoaddress call.
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)

walletinfo = self.nodes[0].getwalletinfo()
walletinfo = self.nodes[0].getwalletinfo("bitcoin")
assert_equal(walletinfo['immature_balance'], 0)

# Have node0 mine a block, thus it will collect its own fee.
self.nodes[0].generate(1)
self.sync_all()

# Exercise locking of unspent outputs
unspent_0 = self.nodes[2].listunspent()[0]
unspent_0 = self.nodes[2].listunspent(1, 9999999, [], "bitcoin")[0]
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
self.nodes[2].lockunspent(False, [unspent_0])
assert_raises(JSONRPCException, self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
Expand All @@ -100,27 +98,29 @@ def run_test (self):

# node0 should end up with 100 btc in block rewards plus fees, but
# minus the 21 plus fees sent to node2
assert_equal(self.nodes[0].getbalance(), 21000000-21-1100000)
assert_equal(self.nodes[2].getbalance(), 100000+21)
assert_equal(self.nodes[0].getbalance("", 0, False, "bitcoin"), 21000000-21)
assert_equal(self.nodes[2].getbalance("", 0, False, "bitcoin"), 21)

# Node0 should have three unspent outputs.
# Node0 should have three non-zero unspent outputs and 101 from generate.
# Create a couple of transactions to send them to node2, submit them through
# node1, and make sure both node0 and node2 pick them up properly:
node0utxos = self.nodes[0].listunspent(1)
assert_equal(len(node0utxos), 206)
node0utxos = self.nodes[0].listunspent(1, 9999999, [], "bitcoin")
assert_equal(len(node0utxos), 104)

# create both transactions
txns_to_send = []
for utxo in node0utxos:
if utxo["amount"] == 100000:
if utxo["amount"] <= 3:
continue
inputs = []
outputs = {}
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - 3
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"], "nValue":utxo["amount"]})
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - Decimal(3)
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
raw_tx = self.nodes[0].blindrawtransaction(raw_tx)
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))

return #TODO Fix the rest
# Have node 1 (miner) send the transactions
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True)
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True)
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/zapwallettxes.py
Expand Up @@ -29,7 +29,7 @@ def run_test (self):
self.nodes[1].generate(101)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 21000000)
assert_equal(self.nodes[0].getbalance()["bitcoin"], 21000000)

txid0 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
txid1 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
Expand Down

0 comments on commit fd3447f

Please sign in to comment.