Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.17, WIP] Confidential Assets #503

Closed
wants to merge 229 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
b12b334
WIP: squashed CA work
stevenroose Jan 29, 2019
f1e0908
Add missing test case files
instagibbs Feb 13, 2019
bfed763
WIP: rebase fixes
stevenroose Feb 13, 2019
5bc6604
cherrypick unblindrawtransaction commit from 0.14
stevenroose Feb 14, 2019
e32b057
assets in tests
stevenroose Feb 15, 2019
7f28284
fixups
stevenroose Feb 19, 2019
a04cb01
REMOVEME: add print statements
stevenroose Feb 19, 2019
caeacf8
Replace CScriptID and CKeyID in CTxDestination with dedicated type
instagibbs Feb 19, 2019
5b05e8b
fixups
stevenroose Feb 19, 2019
b2abf9a
fixups
stevenroose Feb 19, 2019
ee55bab
REMOVEME: more printing
stevenroose Feb 19, 2019
ab12320
WIP: Coin selection
stevenroose Feb 21, 2019
050894a
REMOVEME: printing
stevenroose Feb 21, 2019
9da884a
WIP
stevenroose Feb 21, 2019
2447e69
REMOVEME: printing
stevenroose Feb 22, 2019
ab00a4e
bitcoin_functional working
stevenroose Feb 22, 2019
cd98ff6
Add BITCOIN_ASSET to all occurrences of getbalance()
stevenroose Feb 22, 2019
fac4f53
Make balance responses always contain at least policyAsset
stevenroose Feb 23, 2019
35e4dea
REMOVEME: printing
stevenroose Feb 25, 2019
b12d763
REMOVEME: printing
stevenroose Feb 25, 2019
e91591a
f'Add BITCOIN_ASSET to all occurrences of getbalance()'
stevenroose Feb 25, 2019
1226d63
random fixups
stevenroose Feb 25, 2019
3da00c1
changekey thing
stevenroose Feb 25, 2019
a56b817
fix some change position tracking
stevenroose Feb 25, 2019
1c898a9
Don't allow fees in coinbase transactions
stevenroose Feb 26, 2019
6019152
f'Add BITCOIN_ASSET to all occurrences of getbalance()'
stevenroose Feb 26, 2019
024993e
fixes
stevenroose Feb 26, 2019
ab323c5
SHash to ScriptHash to reflect upstream changes
instagibbs Feb 26, 2019
3d00250
add blinding pubkey to relevant destinations
instagibbs Feb 26, 2019
3f0a5c1
Initialize master blinding derivation key on wallet load if uninitial…
instagibbs Feb 27, 2019
fa84698
Encoding and decoding of blinded addresses, getnewaddress support
instagibbs Feb 27, 2019
e350d95
Add fee outputs to functional tests
stevenroose Feb 27, 2019
5eb4703
f'Add BITCOIN_ASSET to all occurrences of getbalance()'
stevenroose Feb 27, 2019
b07454d
Fix hard-coded tx in functional test
stevenroose Feb 27, 2019
ba2e137
Disable tests that are not relevant for Elements
stevenroose Feb 27, 2019
a6275e5
fix coin selection
stevenroose Feb 27, 2019
b7838a6
f'Disable tests that are not relevant for Elements'
stevenroose Feb 27, 2019
d208bc1
coin selection fixups
stevenroose Feb 27, 2019
7a54504
disabled bech32 CT addresses for now
instagibbs Feb 27, 2019
b5f45d6
Add blinded address introspection in getaddressinfo and validateaddress
instagibbs Feb 27, 2019
33a5bef
listunspent support for asset details, filtering
instagibbs Feb 27, 2019
ecadc4b
getrawchangeaddress blinding
instagibbs Feb 27, 2019
34b3ed2
SendMoney: extract blinding key from destination
instagibbs Feb 27, 2019
418215e
sendmany: add confidential key to receipients
instagibbs Feb 27, 2019
dd11388
maybe support listreceivedby*, labels included?
instagibbs Feb 27, 2019
81334ec
Fee outputs only exist in elements mode
instagibbs Feb 27, 2019
ef1e8b6
listtransactions: support assets
instagibbs Feb 27, 2019
883b0be
cleanup fee for bitcoind mode in listtransaction
instagibbs Feb 27, 2019
47eeab4
getpeginaddress: no need to get unblinded version of address
instagibbs Feb 27, 2019
b88d672
Load pet asset labels from conf file and command line
instagibbs Feb 27, 2019
72d17c8
move asset args to init.cpp
instagibbs Feb 27, 2019
b66224e
add dumpassetlabels
instagibbs Feb 27, 2019
578c931
import(issuance)blindingkey rpc calls
instagibbs Feb 27, 2019
ddfe8c7
Move all elements rpc json parsing in rpc/client.cpp to end, add a bu…
instagibbs Feb 27, 2019
c59a2f7
add TODO for importing master blinding key
instagibbs Feb 27, 2019
016fed1
dump(issuance)blindingkey
instagibbs Feb 28, 2019
f8496ee
raw(re)issueasset
instagibbs Feb 28, 2019
b8ebef9
fixups
stevenroose Feb 28, 2019
49121db
f'Add BITCOIN_ASSET to all occurrences of getbalance()'
stevenroose Feb 28, 2019
4eae8f0
REMOVEME: printing
stevenroose Feb 28, 2019
1ddcb27
(re)issueasset, listissuances calls
instagibbs Feb 28, 2019
a08dbe3
createblindedaddress RPC call
instagibbs Feb 28, 2019
380ce79
fixes
stevenroose Feb 28, 2019
0ae575a
fixup find_vout_for_address with confidential addresses
instagibbs Feb 28, 2019
d06ebfb
f'Add BITCOIN_ASSET to all occurrences of getbalance()'
stevenroose Feb 28, 2019
c370f19
fixing tests
stevenroose Mar 1, 2019
841d146
AmountMapToUniv
stevenroose Mar 1, 2019
e349775
AmountMapToUni to rpc/util.*
instagibbs Mar 1, 2019
f9b94ff
Move PrintAmountMap back and add necessary includes in rpc/util.cpp
instagibbs Mar 1, 2019
3cad894
Add blech32 python implementation with diff annotation with segwit_ad…
instagibbs Mar 1, 2019
b31ca8a
Add blech32 cpp implementation and API
instagibbs Mar 1, 2019
82dfa2b
fix blech32 decoding
instagibbs Mar 1, 2019
c6d7441
Fix non-bech32 CT addresses
instagibbs Mar 1, 2019
4841db0
Implement blech32 addresses, expose over RPC
instagibbs Mar 1, 2019
ac89d18
fixes
stevenroose Mar 1, 2019
9e834fe
test fixes
stevenroose Mar 1, 2019
9c18bb6
blech32 support in chains/coders
instagibbs Mar 1, 2019
7f80448
blech32: grab right pubkey bytes
instagibbs Mar 1, 2019
900189d
Finish getaddressinfo fetch of confidential address types
instagibbs Mar 1, 2019
5a49efd
p2p_invalid.py: Add fee outputs
instagibbs Mar 1, 2019
d63ea79
fix create_transaction, feature_cltv.py
instagibbs Mar 1, 2019
f8ead4a
fix feature_dersig.py
instagibbs Mar 1, 2019
8f15803
fix feature_nulldummy.py
instagibbs Mar 1, 2019
7ed6eeb
still not fixed: feature_csv_activation.py
instagibbs Mar 1, 2019
8f8d557
Fix feature_block.py
stevenroose Mar 4, 2019
fb04f16
Update rpc_getblockstats test data
stevenroose Mar 4, 2019
4f3fdbb
fixes
stevenroose Mar 4, 2019
2fcd64b
fix rbf test
instagibbs Mar 4, 2019
8465114
fix feature_block_v4.py
instagibbs Mar 4, 2019
6fa770f
importmulti: add blinding_privkey arg, fix test
instagibbs Mar 4, 2019
bb42f3b
nit
stevenroose Mar 4, 2019
0a1bb87
segwit test fix
stevenroose Mar 4, 2019
bcf9ab3
Fix wallet compatibility mode
instagibbs Mar 4, 2019
ade61d6
fixes
stevenroose Mar 4, 2019
6a74846
Rename IssuanceDetails->RawIssuanceDetails, make wallet version
instagibbs Mar 4, 2019
7f98912
Add DEFAULT_RANGEPROOF_SIZE constant, test
instagibbs Mar 4, 2019
cd207e9
p2p_segwit
stevenroose Mar 4, 2019
f528177
Stick fee output in end with createrawtransaction, fix bumpfee test n…
instagibbs Mar 5, 2019
4250cdd
Make sure wallet makes change for bumpfee
instagibbs Mar 5, 2019
e8725a9
checkin blinding sends using CreateTransaction
instagibbs Mar 4, 2019
7f343e7
fixup CreateTransaction and add assert in GetBlindingData
instagibbs Mar 5, 2019
4534f51
Wipe blinding data for CWalletTx that are being bumped
instagibbs Mar 5, 2019
d912696
fee output cleanup
stevenroose Mar 5, 2019
6b51175
Fix benchmarks
stevenroose Mar 5, 2019
d9cd258
Add valueFor method
stevenroose Mar 5, 2019
c482b48
Fix Qt build
stevenroose Mar 5, 2019
a8641fe
WIP: porting CA tests from 0.14.1
stevenroose Mar 5, 2019
384f73e
snipe elements pull#480
instagibbs Mar 6, 2019
8e6b3c4
snipe elements pull#472
instagibbs Mar 6, 2019
8b0099c
importblindingkey support for master blinding key
instagibbs Mar 6, 2019
d4e3a77
fixup unit test json response for CA
instagibbs Mar 6, 2019
094bcce
Add secure reporting document, link in README
instagibbs Mar 6, 2019
382e541
fixups
stevenroose Mar 6, 2019
3672f41
check-in issuing and blinding CreateTransaction stuff
instagibbs Mar 5, 2019
323924c
WIP issuance blinding
stevenroose Mar 6, 2019
c6475c7
blinding fixups, compiles but crashes
stevenroose Mar 7, 2019
f94a845
fix (re)issueasset segfault, add more logging
instagibbs Mar 7, 2019
beb4e41
Preserve issuance and input ordering by not wiping inputs
instagibbs Mar 7, 2019
765f78d
remove old checks, normalize witness vectors in CreateTransaction
instagibbs Mar 7, 2019
1faa171
Blinding during issuance working... which breaks everything :)
instagibbs Mar 7, 2019
6fbb69b
move more asset detailing into fillBlinds, stop double-counting asset…
instagibbs Mar 7, 2019
d777de0
Mark GetAmount locations post-tx-blinding
instagibbs Mar 7, 2019
7e1d915
Make MutableTransactionSignatureCreator constructor explicit to avoid…
instagibbs Mar 7, 2019
9cabaa6
derp, comments
instagibbs Mar 7, 2019
9af11f2
Commented out transaction rebalancing, fixme steven
instagibbs Mar 7, 2019
abae40c
Avoid calling GetAmount and GetAsset in CWallet code
stevenroose Mar 8, 2019
ce925d3
fixups
stevenroose Mar 8, 2019
59a0010
REMOVEME: prints
stevenroose Mar 8, 2019
8aa4473
REMOVEME: remove prints
stevenroose Mar 8, 2019
98c0346
fixups
stevenroose Mar 8, 2019
bb39910
issuance test fixups
stevenroose Mar 8, 2019
5bfecc0
panic fix
stevenroose Mar 8, 2019
be7280b
test fixup
stevenroose Mar 8, 2019
6eba7c4
destroyamount
stevenroose Mar 8, 2019
b7e2eb9
we aren't doing audit log anymore
instagibbs Mar 8, 2019
14684f8
f
stevenroose Mar 11, 2019
30843d2
Wipe o_*_blinds between different blindings
instagibbs Mar 11, 2019
0827cf5
fixup
instagibbs Mar 11, 2019
5747d21
print + fix
stevenroose Mar 11, 2019
2aa6570
REMOVEME: printing
stevenroose Mar 11, 2019
9606f53
fixups
stevenroose Mar 11, 2019
ff60ae9
fixups
stevenroose Mar 11, 2019
36e44ce
fixed only recipient field in CreateTransaction
instagibbs Mar 11, 2019
424d27c
fix
stevenroose Mar 11, 2019
e3eac42
Don't use effective_value for unblinded value
stevenroose Mar 11, 2019
7ad54a9
fix
stevenroose Mar 11, 2019
2fae6f1
CreateTransaction: Wipe all witness data in loop as well
instagibbs Mar 11, 2019
bb95103
fixes
stevenroose Mar 12, 2019
62c7e02
REMOVEME: printing
stevenroose Mar 12, 2019
c9bcb0e
test fix
stevenroose Mar 12, 2019
3c98fdb
Fixup createraw/fundraw blinding key, print more in decode
instagibbs Mar 12, 2019
1025164
feature_issuance.py: fund transactions more to not miss min relay wit…
instagibbs Mar 12, 2019
0bf76fd
no panic: explicit was already filtered for
instagibbs Mar 12, 2019
0458f96
listunspent: always return asset regardless of commitment type
instagibbs Mar 12, 2019
2b93e5a
Add rangeproof details to raw tx output
instagibbs Mar 12, 2019
4f6cdfb
fix createrawtransaction arguments for elements
instagibbs Mar 12, 2019
09dc8e2
fixup sendtoaddress help, re-enable ignoreblindfail for sendmany
instagibbs Mar 12, 2019
7bc8054
finish fixing feature_issuance.py
instagibbs Mar 12, 2019
48d635e
add feature_issuance to test_runner
instagibbs Mar 12, 2019
5e1f82d
fix default_asset_name.py and add to test_runner
instagibbs Mar 12, 2019
8ffdb60
test fixes
stevenroose Mar 12, 2019
b09c05f
fixes
stevenroose Mar 13, 2019
1907bb8
fundraw with blinding
stevenroose Mar 13, 2019
917a3fc
no coinbase fees
stevenroose Mar 13, 2019
bafa371
copied confidential test
stevenroose Mar 13, 2019
3c3c4d6
WIP: confidential_transactions test
stevenroose Mar 13, 2019
3bb1b0b
Compare block and utxo db outputs correctly
instagibbs Mar 13, 2019
8779a7a
ASK SIPA: disable sanity check with legacy txo db when connecting gen…
instagibbs Mar 13, 2019
5466aa6
Fix fundraw with blinded destinations
instagibbs Mar 13, 2019
4812ec9
Add some logging on transaction modification due to blinding edge cases
instagibbs Mar 13, 2019
e23eaab
fix fundrawtransaction test
instagibbs Mar 13, 2019
aaf730b
fix default asset name test name
instagibbs Mar 13, 2019
d15f121
fixup default asset name
instagibbs Mar 13, 2019
60d2e5d
fixup elements json results tests one more time
instagibbs Mar 13, 2019
b413d04
fundraw needs to preserve sequence numbers when in blinding mode
instagibbs Mar 13, 2019
bf1abc9
Fix fundraw assert in compatibility mode
instagibbs Mar 13, 2019
92c6a3b
fix feature_assetdir.py
instagibbs Mar 13, 2019
d80009d
feature_fee_estimation: change constants to have it not time out
instagibbs Mar 13, 2019
632b54a
re-add reissuance test
instagibbs Mar 13, 2019
b5616c1
Add test diagnosing help in feature_issuance.py for failures
instagibbs Mar 13, 2019
f07227c
fixing confidential_transactions
stevenroose Mar 13, 2019
7c4ebd3
feature_confidential_transactions works!
stevenroose Mar 14, 2019
6d4d130
set blinding fail in SendMoney
instagibbs Mar 14, 2019
5ad5afd
Fix credit accounting when outputs can't be unblinded
instagibbs Mar 14, 2019
09cd1ce
Actually test blinded multisig issuance
instagibbs Mar 14, 2019
2f86b72
no need to include watching
instagibbs Mar 14, 2019
5b6ecde
unblinding checks
stevenroose Mar 14, 2019
8621d3b
assert GetCredit and add feature_ct to runner
stevenroose Mar 14, 2019
4c83d43
signrawtransactionwith* support signing with prevtxs when given
instagibbs Mar 14, 2019
c8b84d7
address TODOs
stevenroose Mar 14, 2019
4eb6b21
balance stuff fix :|
stevenroose Mar 14, 2019
24ef3a0
WIP: per-asset change script
stevenroose Mar 14, 2019
41cda38
GetTransactionInputWeight: only used for change spend size, assert ex…
instagibbs Mar 14, 2019
5549008
listunspent filter available coins by asset up front for min/max val …
instagibbs Mar 14, 2019
7b30d0d
Leave note on wallet dust calculation
instagibbs Mar 14, 2019
4a6e555
Don't allow encoded empty witnesses
instagibbs Mar 14, 2019
c17c0fa
don't access null output info
instagibbs Mar 14, 2019
5edb90f
WIP (compiles): change destinations
stevenroose Mar 15, 2019
2d4317e
finish change script
stevenroose Mar 15, 2019
ef3ab0e
proposal liquidv1 chainparams
instagibbs Mar 15, 2019
2dce5d8
remove coinbase validation printing
instagibbs Mar 15, 2019
d14a0cb
f'proposal liquidv1 chainparams'
instagibbs Mar 15, 2019
5caad05
blinded addresses
stevenroose Mar 15, 2019
d3d9cd6
remove more printing in validation
instagibbs Mar 15, 2019
303c911
fix liquidv1 addresses
instagibbs Mar 15, 2019
7a1252b
change genesis block creation
stevenroose Mar 15, 2019
b8f57a7
add liquidv1 genesis hash assertion
stevenroose Mar 15, 2019
257695b
use the right liquidv1 magic.... not liquid beta
instagibbs Mar 15, 2019
5275d55
Segwit deployed block 0 in liquidv1
instagibbs Mar 15, 2019
3026d60
Fix witness merkle root for elements
instagibbs Mar 15, 2019
1402221
liquid fedpegscript matching fixup
instagibbs Mar 15, 2019
8cb0e32
report peg-in error message
instagibbs Mar 15, 2019
c4c5f2a
Don't tweak watchman emergency pubkeys
instagibbs Mar 16, 2019
532a47d
calculate_contract needs to continue to end
instagibbs Mar 16, 2019
6e69f56
Sighashing should cover issuance inputs...
instagibbs Mar 16, 2019
77217d2
Sanity check fedpegscript on init
instagibbs Mar 17, 2019
0575a4f
alignment
instagibbs Mar 17, 2019
ce99524
remove unneeded level of indentation
stevenroose Mar 18, 2019
5d13ead
Properly create witness merkle root for elements
instagibbs Mar 18, 2019
aafb120
Elaborate more on witness merkle
instagibbs Mar 18, 2019
16acc5b
witness hash fix in python functional tests
stevenroose Mar 18, 2019
93a4a63
fix a bit of p2p_segwit.py
instagibbs Mar 18, 2019
ea68772
Print more during witness commitment validation
instagibbs Mar 18, 2019
2fa5e39
Switch witness merkle root to handle bitcoin print hashes as strings,…
instagibbs Mar 19, 2019
cb160ea
fix prevout.isNull calculation
instagibbs Mar 19, 2019
bea789d
sighash issuance
stevenroose Mar 19, 2019
d4b3c1c
hashIssuance requires all inputs' data
instagibbs Mar 19, 2019
215f336
missed calc_withess_hash call
instagibbs Mar 19, 2019
a91e8fc
getblockstats
stevenroose Mar 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ Translations are periodically pulled from Transifex and merged into the git repo
pull from Transifex would automatically overwrite them again.

Translators should also subscribe to the [mailing list](https://groups.google.com/forum/#!forum/bitcoin-translators).

Secure Reporting
------------------
See [our vulnerability reporting guide](SECURITY.md)
894 changes: 894 additions & 0 deletions SECURITY.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ if test "x$enable_debug" = xyes; then
# Prefer -Og, fall back to -O0 if that is unavailable.
AX_CHECK_COMPILE_FLAG(
[-Og],
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -Og"]],
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],
[AX_CHECK_COMPILE_FLAG([-O0],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])],
[[$CXXFLAG_WERROR]])

Expand Down Expand Up @@ -1459,7 +1459,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-module-recovery --disable-jni --enable-experimental --enable-module-whitelist --enable-module-rangeproof --enable-module-generator"
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-module-recovery --disable-jni --enable-experimental --enable-module-whitelist --enable-module-rangeproof --enable-module-generator --enable-module-surjectionproof --enable-module-ecdh"
AC_CONFIG_SUBDIRS([src/secp256k1])

AC_OUTPUT
Expand Down
14 changes: 14 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ endif
BITCOIN_CORE_H = \
addrdb.h \
addrman.h \
asset.h \
assetsdir.h \
base58.h \
bech32.h \
blech32.h \
blind.h \
bloom.h \
blockencodings.h \
blockfilter.h \
Expand All @@ -111,6 +115,7 @@ BITCOIN_CORE_H = \
compat/endian.h \
compat/sanity.h \
compressor.h \
confidential_validation.h \
consensus/consensus.h \
consensus/tx_verify.h \
core_io.h \
Expand All @@ -126,6 +131,7 @@ BITCOIN_CORE_H = \
interfaces/handler.h \
interfaces/node.h \
interfaces/wallet.h \
issuance.h \
key.h \
key_io.h \
keystore.h \
Expand Down Expand Up @@ -229,6 +235,7 @@ libbitcoin_server_a_SOURCES = \
block_proof.cpp \
chain.cpp \
checkpoints.cpp \
confidential_validation.cpp \
consensus/tx_verify.cpp \
httprpc.cpp \
httpserver.cpp \
Expand Down Expand Up @@ -290,6 +297,7 @@ endif
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_a_SOURCES = \
assetsdir.cpp \
interfaces/wallet.cpp \
wallet/coincontrol.cpp \
wallet/crypter.cpp \
Expand Down Expand Up @@ -358,6 +366,7 @@ libbitcoin_consensus_a_SOURCES = \
amount.h \
arith_uint256.cpp \
arith_uint256.h \
asset.cpp \
consensus/merkle.cpp \
consensus/merkle.h \
consensus/params.h \
Expand All @@ -367,6 +376,8 @@ libbitcoin_consensus_a_SOURCES = \
prevector.h \
primitives/block.cpp \
primitives/block.h \
primitives/confidential.cpp \
primitives/confidential.h \
primitives/txwitness.cpp \
primitives/txwitness.h \
primitives/transaction.cpp \
Expand Down Expand Up @@ -403,11 +414,14 @@ libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_common_a_SOURCES = \
base58.cpp \
bech32.cpp \
blech32.cpp \
blind.cpp \
chainparams.cpp \
coins.cpp \
compressor.cpp \
core_read.cpp \
core_write.cpp \
issuance.cpp \
key.cpp \
key_io.cpp \
keystore.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ BITCOIN_TESTS =\
test/util_tests.cpp \
test/validation_block_tests.cpp \
test/versionbits_tests.cpp \
test/pegin_spent_tests.cpp
test/pegin_spent_tests.cpp \
test/blind_tests.cpp
# ELEMENTS IN THE END

if ENABLE_PROPERTY_TESTS
Expand Down
160 changes: 160 additions & 0 deletions src/asset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@

#include <asset.h>
#include <assetsdir.h>
#include <core_io.h>
#include <logging.h>
#include <policy/policy.h>


CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
a[it->first] += it->second;
return a;
}

CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
a[it->first] -= it->second;
return a;
}

CAmountMap operator+(const CAmountMap& a, const CAmountMap& b)
{
CAmountMap c;
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
c[it->first] += it->second;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
c[it->first] += it->second;
return c;
}

CAmountMap operator-(const CAmountMap& a, const CAmountMap& b)
{
CAmountMap c;
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
c[it->first] += it->second;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
c[it->first] -= it->second;
return c;
}

bool operator<(const CAmountMap& a, const CAmountMap& b)
{
bool smallerElement = false;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
if (aValue > it->second)
return false;
if (aValue < it->second)
smallerElement = true;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
if (it->second > bValue)
return false;
if (it->second < bValue)
smallerElement = true;
}
return smallerElement;
}

bool operator<=(const CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
if (aValue > it->second)
return false;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
if (it->second > bValue)
return false;
}
return true;
}

bool operator>(const CAmountMap& a, const CAmountMap& b)
{
bool largerElement = false;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
if (aValue < it->second)
return false;
if (aValue > it->second)
largerElement = true;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
if (it->second < bValue)
return false;
if (it->second > bValue)
largerElement = true;
}
return largerElement;
}

bool operator>=(const CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
if ((a.count(it->first) ? a.find(it->first)->second : 0) < it->second)
return false;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
if (it->second < (b.count(it->first) ? b.find(it->first)->second : 0))
return false;
}
return true;
}

bool operator==(const CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
if ((b.count(it->first) ? b.find(it->first)->second : 0) != it->second)
return false;
}
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
if ((a.count(it->first) ? a.find(it->first)->second : 0) != it->second)
return false;
}
return true;
}

bool operator!=(const CAmountMap& a, const CAmountMap& b)
{
return !(a == b);
}

bool hasNegativeValue(const CAmountMap& amount)
{
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
if (it->second < 0)
return true;
}
return false;
}

bool hasNonPostiveValue(const CAmountMap& amount)
{
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
if (it->second <= 0)
return true;
}
return false;
}

CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset) {
CAmountMap::const_iterator it = mapValue.find(asset);
if (it != mapValue.end()) {
return it->second;
} else {
return CAmount(0);
}
}

void PrintAmountMap(const CAmountMap& amount) {
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
LogPrintf("- %s: %s\n", it->first.GetHex(), it->second);
}
}
112 changes: 112 additions & 0 deletions src/asset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

#ifndef BITCOIN_ASSET_H
#define BITCOIN_ASSET_H

#include <stdint.h>
#include <uint256.h>
#include <stdlib.h>

#include <amount.h>
#include <serialize.h>

/**
* Native Asset Issuance
*
* An asset identifier tag, a 256 bits serialized hash (sha256) defined
* by the issuance transaction from which the output’s coins are derived.
* Each output contains coins from a single asset/currency.
* For the host currency, the similarly-calculated hash of the chain’s genesis
* block is used instead.
**/
struct CAsset {
uint256 id;

CAsset() { }
explicit CAsset(const uint256& idIn) : id(idIn) { }
explicit CAsset(const std::vector<unsigned char>& vchIDIn) : id(vchIDIn) { }

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(id);
}

bool IsNull() const { return id.IsNull(); }
void SetNull() { id.SetNull(); }

unsigned char* begin() { return id.begin(); }
unsigned char* end() { return id.end(); }
const unsigned char* begin() const { return id.begin(); }
const unsigned char* end() const { return id.end(); }

std::string GetHex() const { return id.GetHex(); }
void SetHex(const std::string& str) { id.SetHex(str); }

friend bool operator==(const CAsset& a, const CAsset& b)
{
return a.id == b.id;
}

friend bool operator!=(const CAsset& a, const CAsset& b)
{
return !(a == b);
}

friend bool operator<(const CAsset& a, const CAsset& b)
{
return a.id < b.id;
}
};

/** Used for consensus fee and general wallet accounting*/
typedef std::map<CAsset, CAmount> CAmountMap;

CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b);
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b);
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b);
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b);

// WARNING: Comparisons are only looking for *complete* ordering.
// For strict inequality checks, if any entry would fail the non-strict
// inequality, the comparison will fail. Therefore it is possible
// that all inequality comparison checks may fail.
// Therefore if >/< fails against a CAmountMap(), this means there
// are all zeroes or one or more negative values.
//
// Examples: 1A + 2B <= 1A + 2B + 1C
// and 1A + 2B < 1A + 2B + 1C
// but
// !(1A + 2B == 1A + 2B + 1C)
//-------------------------------------
// 1A + 2B == 1A + 2B
// and 1A + 2B <= 1A + 2B
// but
// !(1A + 2B < 1A + 2B)
//-------------------------------------
// !(1A + 2B == 2B - 1C)
// !(1A + 2B >= 2B - 1C)
// ...
// !(1A + 2B < 2B - 1C)
// and 1A + 2B != 2B - 1C
bool operator<(const CAmountMap& a, const CAmountMap& b);
bool operator<=(const CAmountMap& a, const CAmountMap& b);
bool operator>(const CAmountMap& a, const CAmountMap& b);
bool operator>=(const CAmountMap& a, const CAmountMap& b);
bool operator==(const CAmountMap& a, const CAmountMap& b);
bool operator!=(const CAmountMap& a, const CAmountMap& b);

inline bool MoneyRange(const CAmountMap& mapValue) {
for(CAmountMap::const_iterator it = mapValue.begin(); it != mapValue.end(); it++) {
if (it->second < 0 || it->second > MAX_MONEY) {
return false;
}
}
return true;
}

CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset);

void PrintAmountMap(const CAmountMap& amount);

#endif // BITCOIN_AMOUNT_H
Loading