mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Add basic issuance boilerplate
This commit is contained in:
parent
f81122f948
commit
fde9fe1010
4 changed files with 43 additions and 12 deletions
|
|
@ -188,3 +188,20 @@ void CreateValueCommitment(CConfidentialValue& conf_value, secp256k1_pedersen_co
|
||||||
secp256k1_pedersen_commitment_serialize(secp256k1_blind_context, conf_value.vchCommitment.data(), &value_commit);
|
secp256k1_pedersen_commitment_serialize(secp256k1_blind_context, conf_value.vchCommitment.data(), &value_commit);
|
||||||
assert(conf_value.IsValid());
|
assert(conf_value.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t GetNumIssuances(const CTransaction& tx)
|
||||||
|
{
|
||||||
|
unsigned int num_issuances = 0;
|
||||||
|
for (unsigned int i = 0; i < tx.vin.size(); i++) {
|
||||||
|
if (!tx.vin[i].assetIssuance.IsNull()) {
|
||||||
|
if (!tx.vin[i].assetIssuance.nAmount.IsNull()) {
|
||||||
|
num_issuances++;
|
||||||
|
}
|
||||||
|
if (!tx.vin[i].assetIssuance.nInflationKeys.IsNull()) {
|
||||||
|
num_issuances++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num_issuances;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,4 +35,6 @@ void BlindAsset(CConfidentialAsset& conf_asset, secp256k1_generator& asset_gen,
|
||||||
|
|
||||||
void CreateValueCommitment(CConfidentialValue& conf_value, secp256k1_pedersen_commitment& value_commit, const unsigned char* value_blindptr, const secp256k1_generator& asset_gen, const CAmount amount);
|
void CreateValueCommitment(CConfidentialValue& conf_value, secp256k1_pedersen_commitment& value_commit, const unsigned char* value_blindptr, const secp256k1_generator& asset_gen, const CAmount amount);
|
||||||
|
|
||||||
|
size_t GetNumIssuances(const CTransaction& tx);
|
||||||
|
|
||||||
#endif //BITCOIN_WALLET_BLIND_H
|
#endif //BITCOIN_WALLET_BLIND_H
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ std::string CTxIn::ToString() const
|
||||||
str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
|
str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
|
||||||
if (nSequence != SEQUENCE_FINAL)
|
if (nSequence != SEQUENCE_FINAL)
|
||||||
str += strprintf(", nSequence=%u", nSequence);
|
str += strprintf(", nSequence=%u", nSequence);
|
||||||
|
if (!assetIssuance.IsNull())
|
||||||
|
str += strprintf(", %s", assetIssuance.ToString());
|
||||||
str += ")";
|
str += ")";
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
#include <primitives/confidential.h>
|
||||||
#include <primitives/txwitness.h>
|
#include <primitives/txwitness.h>
|
||||||
|
|
||||||
static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000;
|
static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000;
|
||||||
|
|
@ -31,8 +32,7 @@ public:
|
||||||
|
|
||||||
/* If this flag is set, the CTxIn including this COutPoint has a
|
/* If this flag is set, the CTxIn including this COutPoint has a
|
||||||
* CAssetIssuance object. */
|
* CAssetIssuance object. */
|
||||||
//TODO(rebase) CA
|
static const uint32_t OUTPOINT_ISSUANCE_FLAG = (1 << 31);
|
||||||
//static const uint32_t OUTPOINT_ISSUANCE_FLAG = (1 << 31);
|
|
||||||
|
|
||||||
/* If this flag is set, the CTxIn including this COutPoint
|
/* If this flag is set, the CTxIn including this COutPoint
|
||||||
* is a peg-in input. */
|
* is a peg-in input. */
|
||||||
|
|
@ -93,6 +93,8 @@ public:
|
||||||
//
|
//
|
||||||
// ELEMENTS:
|
// ELEMENTS:
|
||||||
|
|
||||||
|
CAssetIssuance assetIssuance;
|
||||||
|
|
||||||
/* If this is set to true, the input is interpreted as a
|
/* If this is set to true, the input is interpreted as a
|
||||||
* peg-in claim and processed as such */
|
* peg-in claim and processed as such */
|
||||||
bool m_is_pegin = false;
|
bool m_is_pegin = false;
|
||||||
|
|
@ -143,14 +145,13 @@ public:
|
||||||
//
|
//
|
||||||
// ELEMENTS:
|
// ELEMENTS:
|
||||||
|
|
||||||
//TODO(rebase) CA/CT
|
bool fHasAssetIssuance;
|
||||||
//bool fHasAssetIssuance;
|
|
||||||
COutPoint outpoint;
|
COutPoint outpoint;
|
||||||
if (!ser_action.ForRead()) {
|
if (!ser_action.ForRead()) {
|
||||||
if (prevout.n == (uint32_t) -1) {
|
if (prevout.n == (uint32_t) -1) {
|
||||||
// Coinbase inputs do not have asset issuances attached
|
// Coinbase inputs do not have asset issuances attached
|
||||||
// to them.
|
// to them.
|
||||||
// fHasAssetIssuance = false;
|
fHasAssetIssuance = false;
|
||||||
outpoint = prevout;
|
outpoint = prevout;
|
||||||
} else {
|
} else {
|
||||||
// The issuance and pegin bits can't be set as it is used to indicate
|
// The issuance and pegin bits can't be set as it is used to indicate
|
||||||
|
|
@ -160,15 +161,15 @@ public:
|
||||||
assert(!(prevout.n & ~COutPoint::OUTPOINT_INDEX_MASK));
|
assert(!(prevout.n & ~COutPoint::OUTPOINT_INDEX_MASK));
|
||||||
// The assetIssuance object is used to represent both new
|
// The assetIssuance object is used to represent both new
|
||||||
// asset generation and reissuance of existing asset types.
|
// asset generation and reissuance of existing asset types.
|
||||||
// fHasAssetIssuance = !assetIssuance.IsNull();
|
fHasAssetIssuance = !assetIssuance.IsNull();
|
||||||
// The mode is placed in the upper bits of the outpoint's
|
// The mode is placed in the upper bits of the outpoint's
|
||||||
// index field. The IssuanceMode enum values are chosen to
|
// index field. The IssuanceMode enum values are chosen to
|
||||||
// make this as simple as a bitwise-OR.
|
// make this as simple as a bitwise-OR.
|
||||||
outpoint.hash = prevout.hash;
|
outpoint.hash = prevout.hash;
|
||||||
outpoint.n = prevout.n & COutPoint::OUTPOINT_INDEX_MASK;
|
outpoint.n = prevout.n & COutPoint::OUTPOINT_INDEX_MASK;
|
||||||
// if (fHasAssetIssuance) {
|
if (fHasAssetIssuance) {
|
||||||
// outpoint.n |= COutPoint::OUTPOINT_ISSUANCE_FLAG;
|
outpoint.n |= COutPoint::OUTPOINT_ISSUANCE_FLAG;
|
||||||
// }
|
}
|
||||||
if (m_is_pegin) {
|
if (m_is_pegin) {
|
||||||
outpoint.n |= COutPoint::OUTPOINT_PEGIN_FLAG;
|
outpoint.n |= COutPoint::OUTPOINT_PEGIN_FLAG;
|
||||||
}
|
}
|
||||||
|
|
@ -180,13 +181,13 @@ public:
|
||||||
if (ser_action.ForRead()) {
|
if (ser_action.ForRead()) {
|
||||||
if (outpoint.n == (uint32_t) -1) {
|
if (outpoint.n == (uint32_t) -1) {
|
||||||
// No asset issuance for Coinbase inputs.
|
// No asset issuance for Coinbase inputs.
|
||||||
// fHasAssetIssuance = false;
|
fHasAssetIssuance = false;
|
||||||
prevout = outpoint;
|
prevout = outpoint;
|
||||||
m_is_pegin = false;
|
m_is_pegin = false;
|
||||||
} else {
|
} else {
|
||||||
// The presence of the asset issuance object is indicated by
|
// The presence of the asset issuance object is indicated by
|
||||||
// a bit set in the outpoint index field.
|
// a bit set in the outpoint index field.
|
||||||
// fHasAssetIssuance = !!(outpoint.n & COutPoint::OUTPOINT_ISSUANCE_FLAG);
|
fHasAssetIssuance = !!(outpoint.n & COutPoint::OUTPOINT_ISSUANCE_FLAG);
|
||||||
// The interpretation of this input as a peg-in is indicated by
|
// The interpretation of this input as a peg-in is indicated by
|
||||||
// a bit set in the outpoint index field.
|
// a bit set in the outpoint index field.
|
||||||
m_is_pegin = !!(outpoint.n & COutPoint::OUTPOINT_PEGIN_FLAG);
|
m_is_pegin = !!(outpoint.n & COutPoint::OUTPOINT_PEGIN_FLAG);
|
||||||
|
|
@ -204,13 +205,22 @@ public:
|
||||||
|
|
||||||
READWRITE(scriptSig);
|
READWRITE(scriptSig);
|
||||||
READWRITE(nSequence);
|
READWRITE(nSequence);
|
||||||
|
|
||||||
|
// ELEMENTS:
|
||||||
|
// The asset fields are deserialized only if they are present.
|
||||||
|
if (fHasAssetIssuance) {
|
||||||
|
READWRITE(assetIssuance);
|
||||||
|
} else if (ser_action.ForRead()) {
|
||||||
|
assetIssuance.SetNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(const CTxIn& a, const CTxIn& b)
|
friend bool operator==(const CTxIn& a, const CTxIn& b)
|
||||||
{
|
{
|
||||||
return (a.prevout == b.prevout &&
|
return (a.prevout == b.prevout &&
|
||||||
a.scriptSig == b.scriptSig &&
|
a.scriptSig == b.scriptSig &&
|
||||||
a.nSequence == b.nSequence);
|
a.nSequence == b.nSequence &&
|
||||||
|
a.assetIssuance == b.assetIssuance);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator!=(const CTxIn& a, const CTxIn& b)
|
friend bool operator!=(const CTxIn& a, const CTxIn& b)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue