Skip to content

Commit

Permalink
Add basic issuance boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Mar 20, 2019
1 parent f81122f commit fde9fe1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/blind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

2 changes: 2 additions & 0 deletions src/blind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
34 changes: 22 additions & 12 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,8 +32,7 @@ class COutPoint

/* 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. */
Expand Down Expand Up @@ -93,6 +93,8 @@ class CTxIn
//
// 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;
Expand Down Expand Up @@ -143,14 +145,13 @@ class CTxIn
//
// 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
Expand All @@ -160,15 +161,15 @@ class CTxIn
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;
}
Expand All @@ -180,13 +181,13 @@ class CTxIn
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);
Expand All @@ -204,13 +205,22 @@ class CTxIn

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)
Expand Down

0 comments on commit fde9fe1

Please sign in to comment.