diff --git a/src/Makefile.am b/src/Makefile.am index ad0f45034d..67037e8853 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -373,6 +373,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 \ diff --git a/src/primitives/confidential.cpp b/src/primitives/confidential.cpp new file mode 100644 index 0000000000..fd1a9eca0d --- /dev/null +++ b/src/primitives/confidential.cpp @@ -0,0 +1,34 @@ + +#include + +#include + +void CConfidentialAsset::SetToAsset(const CAsset& asset) +{ + vchCommitment.clear(); + vchCommitment.reserve(nExplicitSize); + vchCommitment.push_back(1); + vchCommitment.insert(vchCommitment.end(), asset.begin(), asset.end()); +} + +void CConfidentialValue::SetToAmount(const CAmount amount) +{ + vchCommitment.resize(nExplicitSize); + vchCommitment[0] = 1; + WriteBE64(&vchCommitment[1], amount); +} + +std::string CAssetIssuance::ToString() const +{ + std::string str; + str += "CAssetIssuance("; + str += assetBlindingNonce.ToString(); + str += ", "; + str += assetEntropy.ToString(); + if (!nAmount.IsNull()) + str += strprintf(", amount=%s", (nAmount.IsExplicit() ? strprintf("%d.%08d", nAmount.GetAmount() / COIN, nAmount.GetAmount() % COIN) : std::string("CONFIDENTIAL"))); + if (!nInflationKeys.IsNull()) + str += strprintf(", inflationkeys=%s", (nInflationKeys.IsExplicit() ? strprintf("%d.%08d", nInflationKeys.GetAmount() / COIN, nInflationKeys.GetAmount() % COIN) : std::string("CONFIDENTIAL"))); + str += ")"; + return str; +} diff --git a/src/primitives/confidential.h b/src/primitives/confidential.h new file mode 100644 index 0000000000..b404f84a3d --- /dev/null +++ b/src/primitives/confidential.h @@ -0,0 +1,224 @@ + +#ifndef BITCOIN_PRIMITIVES_CONFIDENTIAL_H +#define BITCOIN_PRIMITIVES_CONFIDENTIAL_H + +#include +#include +#include