Skip to content

Commit 36b3ab1

Browse files
committed
add serialization flag support for peg-in inputs
1 parent 9a9ac25 commit 36b3ab1

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/primitives/transaction.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,18 @@ class COutPoint
255255
uint256 hash;
256256
uint32_t n;
257257

258-
/* If this flag set, the CTxIn including this COutPoint has a
258+
/* If this flag is set, the CTxIn including this COutPoint has a
259259
* CAssetIssuance object. */
260260
static const uint32_t OUTPOINT_ISSUANCE_FLAG = (1 << 31);
261261

262+
/* If this flag is set, the CTxIn including this COutPoint
263+
* is a peg-in input. */
264+
static const uint32_t OUTPOINT_PEGIN_FLAG = (1 << 30);
265+
262266
/* The inverse of the combination of the preceeding flags. Used to
263267
* extract the original meaning of `n` as the index into the
264268
* transaction's output array. */
265-
static const uint32_t OUTPOINT_INDEX_MASK = 0x7fffffff;
269+
static const uint32_t OUTPOINT_INDEX_MASK = 0x3fffffff;
266270

267271
COutPoint() { SetNull(); }
268272
COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; }
@@ -376,6 +380,9 @@ class CTxIn
376380
CScript scriptSig;
377381
uint32_t nSequence;
378382
CAssetIssuance assetIssuance;
383+
/* If this is set to true, the input is interpreted as a
384+
* peg-in claim and processed as such */
385+
bool m_is_pegin = false;
379386

380387
/* Setting nSequence to this value for every input in a transaction
381388
* disables nLockTime. */
@@ -426,10 +433,10 @@ class CTxIn
426433
fHasAssetIssuance = false;
427434
outpoint = prevout;
428435
} else {
429-
// The issuance bit can't be set as it is used to indicate
430-
// the presence of the asset issuance or objects. It should
436+
// The issuance and pegin bits can't be set as it is used to indicate
437+
// the presence of the asset issuance or pegin objects. They should
431438
// never be set anyway as that would require a parent
432-
// transaction with over two billion outputs.
439+
// transaction with over one billion outputs.
433440
assert(!(prevout.n & ~COutPoint::OUTPOINT_INDEX_MASK));
434441
// The assetIssuance object is used to represent both new
435442
// asset generation and reissuance of existing asset types.
@@ -442,6 +449,9 @@ class CTxIn
442449
if (fHasAssetIssuance) {
443450
outpoint.n |= COutPoint::OUTPOINT_ISSUANCE_FLAG;
444451
}
452+
if (m_is_pegin) {
453+
outpoint.n |= COutPoint::OUTPOINT_PEGIN_FLAG;
454+
}
445455
}
446456
}
447457

@@ -452,10 +462,14 @@ class CTxIn
452462
// No asset issuance for Coinbase inputs.
453463
fHasAssetIssuance = false;
454464
prevout = outpoint;
465+
m_is_pegin = false;
455466
} else {
456-
// The presense of the asset issuance object is indicated by
467+
// The presence of the asset issuance object is indicated by
457468
// a bit set in the outpoint index field.
458469
fHasAssetIssuance = !!(outpoint.n & COutPoint::OUTPOINT_ISSUANCE_FLAG);
470+
// The interpretation of this input as a peg-in is indicated by
471+
// a bit set in the outpoint index field.
472+
m_is_pegin = !!(outpoint.n & COutPoint::OUTPOINT_PEGIN_FLAG);
459473
// The mode, if set, must be masked out of the outpoint so
460474
// that the in-memory index field retains its traditional
461475
// meaning of identifying the index into the output array

0 commit comments

Comments
 (0)