Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimon committed Aug 10, 2018
1 parent 895588e commit 502357a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions qa/rpc-tests/feature_fedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def setup_network(self, split=False):
connect_nodes_bi(self.nodes, 0, 1)
self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
print('parentgenesisblockhash', self.parentgenesisblockhash)
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
print('parent_pegged_asset', parent_pegged_asset)

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

Expand Down
1 change: 1 addition & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class CCustomParams : public CChainParams {
consensus.pegin_min_depth = GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH);
consensus.mandatory_coinbase_destination = StrHexToScriptWithDefault(GetArg("-con_mandatorycoinbase", ""), CScript()); // Blank script allows any coinbase destination
consensus.parent_chain_signblockscript = StrHexToScriptWithDefault(GetArg("-con_parent_chain_signblockscript", ""), CScript());
consensus.pegged_asset.SetHex(GetArg("-con_parent_pegged_asset", "0x00"));

// bitcoin regtest is the parent chain by default
parentGenesisBlockHash = uint256S(GetArg("-parentgenesisblockhash", "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct Params {
CScript signblockscript;
bool has_parent_chain;
CScript parent_chain_signblockscript;
CAsset parent_pegged_asset;
bool ParentChainHasPow() const { return parent_chain_signblockscript == CScript();}
};
} // namespace Consensus
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-parentpubkeyprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 pubkey address. (default: %d)"), 111));
strUsage += HelpMessageOpt("-parentscriptprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 script address. (default: %d)"), 196));
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])"));
strUsage += HelpMessageOpt("-con_parent_pegged_asset=<hex>", _("Asset ID (hex) for pegged asset for when parent chain has CA. (default: 0x00)"));
}
strUsage += HelpMessageOpt("-validatepegin", strprintf(_("Validate pegin claims. All functionaries must run this. (default: %u)"), DEFAULT_VALIDATE_PEGIN));
strUsage += HelpMessageOpt("-mainchainrpchost=<addr>", strprintf("The address which the daemon will try to connect to validate peg-ins, if enabled. (default: cookie auth)"));
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ UniValue getsidechaininfo(const JSONRPCRequest& request)
"\nExamples:\n"
+ HelpExampleCli("getsidechaininfo", "")
+ HelpExampleRpc("getsidechaininfo", "")
// TODO Update docs
);

LOCK(cs_main);
Expand All @@ -1129,6 +1130,7 @@ UniValue getsidechaininfo(const JSONRPCRequest& request)
if (!consensus.ParentChainHasPow()) {
obj.push_back(Pair("parent_chain_signblockscript_asm", ScriptToAsmStr(consensus.parent_chain_signblockscript)));
obj.push_back(Pair("parent_chain_signblockscript_hex", HexStr(consensus.parent_chain_signblockscript)));
obj.push_back(Pair("parent_pegged_asset", HexStr(consensus.parent_pegged_asset)));
}
return obj;
}
Expand Down
6 changes: 6 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,12 @@ bool GetAmountFromParentChainPegin(CAmount& amount, const CTransaction& txBTC, u
if (!txBTC.vout[nOut].nValue.IsExplicit()) {
return false;
}
if (!txBTC.vout[nOut].nAsset.IsExplicit()) {
return false;
}
if (txBTC.vout[nOut].nAsset.GetAsset() != Params().GetConsensus().parent_pegged_asset) {
return false;
}
amount = txBTC.vout[nOut].nValue.GetAmount();
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3625,7 +3625,8 @@ static UniValue createrawpegin(const JSONRPCRequest& request, T_tx_ref& txBTCRef

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

CDataStream stream(0, 0);
Expand Down

0 comments on commit 502357a

Please sign in to comment.