mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +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);
|
||||
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);
|
||||
|
||||
size_t GetNumIssuances(const CTransaction& tx);
|
||||
|
||||
#endif //BITCOIN_WALLET_BLIND_H
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ std::string CTxIn::ToString() const
|
|||
str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
|
||||
if (nSequence != SEQUENCE_FINAL)
|
||||
str += strprintf(", nSequence=%u", nSequence);
|
||||
if (!assetIssuance.IsNull())
|
||||
str += strprintf(", %s", assetIssuance.ToString());
|
||||
str += ")";
|
||||
return str;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <script/script.h>
|
||||
#include <serialize.h>
|
||||
#include <uint256.h>
|
||||
#include <primitives/confidential.h>
|
||||
#include <primitives/txwitness.h>
|
||||
|
||||
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
|
||||
* 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
|
||||
* is a peg-in input. */
|
||||
|
|
@ -93,6 +93,8 @@ public:
|
|||
//
|
||||
// ELEMENTS:
|
||||
|
||||
CAssetIssuance assetIssuance;
|
||||
|
||||
/* If this is set to true, the input is interpreted as a
|
||||
* peg-in claim and processed as such */
|
||||
bool m_is_pegin = false;
|
||||
|
|
@ -143,14 +145,13 @@ public:
|
|||
//
|
||||
// ELEMENTS:
|
||||
|
||||
//TODO(rebase) CA/CT
|
||||
//bool fHasAssetIssuance;
|
||||
bool fHasAssetIssuance;
|
||||
COutPoint outpoint;
|
||||
if (!ser_action.ForRead()) {
|
||||
if (prevout.n == (uint32_t) -1) {
|
||||
// Coinbase inputs do not have asset issuances attached
|
||||
// to them.
|
||||
// fHasAssetIssuance = false;
|
||||
fHasAssetIssuance = false;
|
||||
outpoint = prevout;
|
||||
} else {
|
||||
// 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));
|
||||
// The assetIssuance object is used to represent both new
|
||||
// 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
|
||||
// index field. The IssuanceMode enum values are chosen to
|
||||
// make this as simple as a bitwise-OR.
|
||||
outpoint.hash = prevout.hash;
|
||||
outpoint.n = prevout.n & COutPoint::OUTPOINT_INDEX_MASK;
|
||||
// if (fHasAssetIssuance) {
|
||||
// outpoint.n |= COutPoint::OUTPOINT_ISSUANCE_FLAG;
|
||||
// }
|
||||
if (fHasAssetIssuance) {
|
||||
outpoint.n |= COutPoint::OUTPOINT_ISSUANCE_FLAG;
|
||||
}
|
||||
if (m_is_pegin) {
|
||||
outpoint.n |= COutPoint::OUTPOINT_PEGIN_FLAG;
|
||||
}
|
||||
|
|
@ -180,13 +181,13 @@ public:
|
|||
if (ser_action.ForRead()) {
|
||||
if (outpoint.n == (uint32_t) -1) {
|
||||
// No asset issuance for Coinbase inputs.
|
||||
// fHasAssetIssuance = false;
|
||||
fHasAssetIssuance = false;
|
||||
prevout = outpoint;
|
||||
m_is_pegin = false;
|
||||
} else {
|
||||
// The presence of the asset issuance object is indicated by
|
||||
// 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
|
||||
// a bit set in the outpoint index field.
|
||||
m_is_pegin = !!(outpoint.n & COutPoint::OUTPOINT_PEGIN_FLAG);
|
||||
|
|
@ -204,13 +205,22 @@ public:
|
|||
|
||||
READWRITE(scriptSig);
|
||||
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)
|
||||
{
|
||||
return (a.prevout == b.prevout &&
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue