Skip to content

Commit abc8305

Browse files
committed
wip
1 parent 895588e commit abc8305

7 files changed

Lines changed: 20 additions & 2 deletions

File tree

qa/rpc-tests/feature_fedpeg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def setup_network(self, split=False):
6161
connect_nodes_bi(self.nodes, 0, 1)
6262
self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
6363
print('parentgenesisblockhash', self.parentgenesisblockhash)
64+
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
65+
print('parent_pegged_asset', parent_pegged_asset)
6466

6567
# Sidechain args
6668
parent_chain_signblockscript = '51'
@@ -80,6 +82,7 @@ def setup_network(self, split=False):
8082
'-parentpubkeyprefix=235',
8183
'-parentscriptprefix=75',
8284
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
85+
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
8386
])
8487
self.nodes.append(start_node(n + 2, self.options.tmpdir, self.extra_args[n + 2], chain='sidechain'))
8588

src/chainparams.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class CCustomParams : public CChainParams {
131131
consensus.pegin_min_depth = GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH);
132132
consensus.mandatory_coinbase_destination = StrHexToScriptWithDefault(GetArg("-con_mandatorycoinbase", ""), CScript()); // Blank script allows any coinbase destination
133133
consensus.parent_chain_signblockscript = StrHexToScriptWithDefault(GetArg("-con_parent_chain_signblockscript", ""), CScript());
134+
consensus.parent_pegged_asset.SetHex(GetArg("-con_parent_pegged_asset", "0x00"));
134135

135136
// bitcoin regtest is the parent chain by default
136137
parentGenesisBlockHash = uint256S(GetArg("-parentgenesisblockhash", "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct Params {
7474
CScript signblockscript;
7575
bool has_parent_chain;
7676
CScript parent_chain_signblockscript;
77+
CAsset parent_pegged_asset;
7778
bool ParentChainHasPow() const { return parent_chain_signblockscript == CScript();}
7879
};
7980
} // namespace Consensus

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ std::string HelpMessage(HelpMessageMode mode)
519519
strUsage += HelpMessageOpt("-parentpubkeyprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 pubkey address. (default: %d)"), 111));
520520
strUsage += HelpMessageOpt("-parentscriptprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 script address. (default: %d)"), 196));
521521
strUsage += HelpMessageOpt("-con_parent_chain_signblockscript", _("Whether parent chain uses pow or signed blocks. If the parent chain uses signed blocks, the challenge (scriptPubKey) script. If not, an empty string. (default: empty script [ie parent uses pow])"));
522+
strUsage += HelpMessageOpt("-con_parent_pegged_asset=<hex>", _("Asset ID (hex) for pegged asset for when parent chain has CA. (default: 0x00)"));
522523
}
523524
strUsage += HelpMessageOpt("-validatepegin", strprintf(_("Validate pegin claims. All functionaries must run this. (default: %u)"), DEFAULT_VALIDATE_PEGIN));
524525
strUsage += HelpMessageOpt("-mainchainrpchost=<addr>", strprintf("The address which the daemon will try to connect to validate peg-ins, if enabled. (default: cookie auth)"));

src/rpc/blockchain.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,14 @@ UniValue getsidechaininfo(const JSONRPCRequest& request)
11051105
"Returns an object containing various state info regarding sidechain functionality.\n"
11061106
"\nResult:\n"
11071107
"{\n"
1108-
" \"fedpegscript\": \"xxxx\", (string) The fedpegscript in hex\n"
1108+
" \"fedpegscript\": \"xxxx\", (string) The fedpegscript in hex\n"
11091109
" \"pegged_asset\" : \"xxxx\", (string) Pegged asset type in hex\n"
11101110
" \"min_peg_diff\" : \"xxxx\", (string) The minimum difficulty parent chain header target. Peg-in headers that have less work will be rejected as an anti-Dos measure.\n"
11111111
" \"parent_blockhash\" : \"xxxx\", (string) The parent genesis blockhash as source of pegged-in funds.\n"
1112+
" \"parent_chain_has_pow\": \"xxxx\", (boolean) Whether parent chain has pow or signed blocks.\n"
1113+
" \"parent_chain_signblockscript_asm\": \"xxxx\", (string) If the parent chain has signed blocks, its signblockscript in ASM.\n"
1114+
" \"parent_chain_signblockscript_hex\": \"xxxx\", (string) If the parent chain has signed blocks, its signblockscript in hex.\n"
1115+
" \"parent_pegged_asset\": \"xxxx\", (boolean) If the parent chain has Confidential Assets, the asset id of the pegged asset in that chain.\n"
11121116
"}\n"
11131117
"\nExamples:\n"
11141118
+ HelpExampleCli("getsidechaininfo", "")
@@ -1129,6 +1133,7 @@ UniValue getsidechaininfo(const JSONRPCRequest& request)
11291133
if (!consensus.ParentChainHasPow()) {
11301134
obj.push_back(Pair("parent_chain_signblockscript_asm", ScriptToAsmStr(consensus.parent_chain_signblockscript)));
11311135
obj.push_back(Pair("parent_chain_signblockscript_hex", HexStr(consensus.parent_chain_signblockscript)));
1136+
obj.push_back(Pair("parent_pegged_asset", HexStr(consensus.parent_pegged_asset)));
11321137
}
11331138
return obj;
11341139
}

src/validation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,12 @@ bool GetAmountFromParentChainPegin(CAmount& amount, const CTransaction& txBTC, u
23802380
if (!txBTC.vout[nOut].nValue.IsExplicit()) {
23812381
return false;
23822382
}
2383+
if (!txBTC.vout[nOut].nAsset.IsExplicit()) {
2384+
return false;
2385+
}
2386+
if (txBTC.vout[nOut].nAsset.GetAsset() != Params().GetConsensus().parent_pegged_asset) {
2387+
return false;
2388+
}
23832389
amount = txBTC.vout[nOut].nValue.GetAmount();
23842390
return true;
23852391
}

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3625,7 +3625,8 @@ static UniValue createrawpegin(const JSONRPCRequest& request, T_tx_ref& txBTCRef
36253625

36263626
CAmount value = 0;
36273627
if (!GetAmountFromParentChainPegin(value, txBTC, nOut)) {
3628-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Amounts to pegin must be explicit");
3628+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Amounts to pegin must be explicit and asset must be %s",
3629+
Params().GetConsensus().parent_pegged_asset.GetHex()));
36293630
}
36303631

36313632
CDataStream stream(0, 0);

0 commit comments

Comments
 (0)