-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: asset lock tx v2 with basic RPC support + tests #7294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
984546b
4e48123
d6edb15
5dfbeec
31d5b2d
0571520
d82933d
2a433c6
4989398
7910536
23b1678
cc358d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,16 +28,17 @@ class BlockManager; | |||||
| class CAssetLockPayload | ||||||
| { | ||||||
| public: | ||||||
| static constexpr uint8_t CURRENT_VERSION = 1; | ||||||
| static constexpr uint8_t INITIAL_VERSION = 1; | ||||||
| static constexpr uint8_t CURRENT_VERSION = 2; | ||||||
| static constexpr auto SPECIALTX_TYPE = TRANSACTION_ASSET_LOCK; | ||||||
|
|
||||||
| private: | ||||||
| uint8_t nVersion{CURRENT_VERSION}; | ||||||
| std::vector<CTxOut> creditOutputs; | ||||||
|
|
||||||
| public: | ||||||
| explicit CAssetLockPayload(const std::vector<CTxOut>& creditOutputs) : | ||||||
| creditOutputs(creditOutputs) | ||||||
| explicit CAssetLockPayload(const std::vector<CTxOut>& creditOutputs, uint8_t nVersion = CURRENT_VERSION) : | ||||||
| nVersion(nVersion), creditOutputs(creditOutputs) | ||||||
| {} | ||||||
|
|
||||||
| CAssetLockPayload() = default; | ||||||
|
|
@@ -154,7 +155,7 @@ class CAssetUnlockPayload | |||||
| } | ||||||
| }; | ||||||
|
|
||||||
| bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state); | ||||||
| bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active = false); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Require the activation flag at every call site. Defaulting Suggested change-bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active = false);
+bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state, bool is_v24_active);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| bool CheckAssetUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, const std::optional<CRangesSet>& indexes, TxValidationState& state); | ||||||
| bool GetAssetUnlockFee(const CTransaction& tx, CAmount& txfee, TxValidationState& state); | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |
| #include <util/std23.h> | ||
|
|
||
| #include <core_io.h> | ||
| #include <key_io.h> | ||
| #include <rpc/util.h> | ||
| #include <script/standard.h> | ||
| #include <util/check.h> | ||
|
|
||
| #include <univalue.h> | ||
|
|
@@ -114,7 +116,9 @@ RPCResult CAssetLockPayload::GetJsonHelp(const std::string& key, bool optional) | |
| {RPCResult::Type::STR, "asm", "The asm"}, | ||
| {RPCResult::Type::STR_HEX, "hex", "The hex"}, | ||
| {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, | ||
| }}}}}} | ||
| }}, | ||
| {RPCResult::Type::STR, "address", /*optional=*/true, "DIP-18 Platform address (version >= 2 only)"}, | ||
| }}}} | ||
|
Comment on lines
+119
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nest platform The new field is currently emitted as Suggested patch@@
{RPCResult::Type::OBJ, "scriptPubKey", "", {
{RPCResult::Type::STR, "asm", "The asm"},
{RPCResult::Type::STR_HEX, "hex", "The hex"},
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
- }},
- {RPCResult::Type::STR, "address", /*optional=*/true, "DIP-18 Platform address (version >= 2 only)"},
+ {RPCResult::Type::STR, "address", /*optional=*/true, "DIP-18 Platform address (version >= 2 only)"},
+ }},
}}}}
@@
UniValue spk(UniValue::VOBJ);
ScriptToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false);
- out.pushKV("scriptPubKey", spk);
if (nVersion >= 2) {
CTxDestination dest;
if (ExtractDestination(credit_output.scriptPubKey, dest)) {
if (const auto* pkh = std::get_if<PKHash>(&dest)) {
- out.pushKV("address", EncodePlatformDestination(PlatformP2PKHDestination(uint160(*pkh))));
+ spk.pushKV("address", EncodePlatformDestination(PlatformP2PKHDestination(uint160(*pkh))));
} else if (const auto* sh = std::get_if<ScriptHash>(&dest)) {
- out.pushKV("address", EncodePlatformDestination(PlatformP2SHDestination(uint160(*sh))));
+ spk.pushKV("address", EncodePlatformDestination(PlatformP2SHDestination(uint160(*sh))));
}
}
}
+ out.pushKV("scriptPubKey", spk);Also applies to: 117-128 🤖 Prompt for AI Agents |
||
| }}; | ||
| } | ||
|
|
||
|
|
@@ -128,6 +132,16 @@ UniValue CAssetLockPayload::ToJson() const | |
| UniValue spk(UniValue::VOBJ); | ||
| ScriptToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false); | ||
| out.pushKV("scriptPubKey", spk); | ||
| if (nVersion >= 2) { | ||
| CTxDestination dest; | ||
| if (ExtractDestination(credit_output.scriptPubKey, dest)) { | ||
| if (const auto* pkh = std::get_if<PKHash>(&dest)) { | ||
| out.pushKV("address", EncodePlatformDestination(PlatformP2PKHDestination(uint160(*pkh)))); | ||
| } else if (const auto* sh = std::get_if<ScriptHash>(&dest)) { | ||
| out.pushKV("address", EncodePlatformDestination(PlatformP2SHDestination(uint160(*sh)))); | ||
| } | ||
| } | ||
| } | ||
| outputs.push_back(out); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Move the payload constructor change into the feature commit
Commit
4e48123is labeled as a regression-test commit but changes the productionCAssetLockPayloadAPI to accept an explicit version. Explicit version construction is part of the version-2 implementation and is needed to construct compatible version-1 payloads afterCURRENT_VERSIONbecomes 2. Move this header hunk into984546band keep4e48123limited to tests.source: ['codex']