Skip to content

Commit

Permalink
Normalize ERC55 terminology and enable listing received (#2293)
Browse files Browse the repository at this point in the history
* Finalize OP_RETURN default rules

* Cleanup coinbase rewards, getblock

* Cleanup reverse

* Revert "Finalize OP_RETURN default rules"

This reverts commit 87d70f4.

* Add ToUniValue

* Include vminfo on getblock

* Add support for Coinbase

* Multi-layered verbosity

* Normalize ERC55 terminology; allow list received

* Refine ToUniValue methods

* Reduce noise

* Avoid confusing names for non UTXO rewards

* Further cleanups

* Minor format cleanup

* Use version terminology

* Pas blockreward by value

* Restore apply/reverse coinbase behaviour

* Update for tokenReward renames

* evm_dfi_lookup

* Restore hiding ETH addresses

* Add comments

---------

Co-authored-by: Bushstar <[email protected]>
  • Loading branch information
prasannavl and Bushstar authored Aug 8, 2023
1 parent 0f294f3 commit e9a6ccb
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DestinationEncoder
std::string operator()(const WitnessV16EthHash& id) const
{
// Raw addr = ETH_ADDR_PREFIX + HexStr(id);
// Produce ETH checksum address: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
// Produce ERC55 checksum address: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
const auto address = HexStr(id);
std::vector<unsigned char> input(address.begin(), address.end());
std::vector<unsigned char> output;
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3897,7 +3897,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
if (!res)
return res;
} else if (src.domain == static_cast<uint8_t>(VMDomain::EVM)) {
// Subtract balance from ETH address
// Subtract balance from ERC55 address
CTxDestination dest;
ExtractDestination(src.address, dest);
const auto fromAddress = std::get<WitnessV16EthHash>(dest);
Expand Down Expand Up @@ -3932,7 +3932,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
if (!res)
return res;
} else if (dst.domain == static_cast<uint8_t>(VMDomain::EVM)) {
// Add balance to ETH address
// Add balance to ERC55 address
CTxDestination dest;
ExtractDestination(dst.address, dest);
const auto toAddress = std::get<WitnessV16EthHash>(dest);
Expand Down
32 changes: 16 additions & 16 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ UniValue gettokenbalances(const JSONRPCRequest& request) {
"Format of amounts output (default = false): (true: obj = {tokenid:amount,...}, false: array = [\"amount@tokenid\"...])"},
{"symbol_lookup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED,
"Use token symbols in output (default = false)"},
{"include_eth", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED,
"Whether to include Eth balances in output (default = false)"},
{"evm", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED,
"Include DFI balances in the EVM layer (default = false): Note: This does not include DST20 tokens"},
},
RPCResult{
"{...} (array) Json object with balances information\n"
Expand Down Expand Up @@ -577,9 +577,9 @@ UniValue gettokenbalances(const JSONRPCRequest& request) {
if (request.params.size() > 2) {
symbol_lookup = request.params[2].getBool();
}
auto eth_lookup = false;
auto evm_dfi_lookup = false;
if (request.params.size() > 3) {
eth_lookup = request.params[3].getBool();
evm_dfi_lookup = request.params[3].getBool();
}

UniValue ret(UniValue::VARR);
Expand All @@ -604,7 +604,7 @@ UniValue gettokenbalances(const JSONRPCRequest& request) {
return true;
});

if (eth_lookup) {
if (evm_dfi_lookup) {
for (const auto keyID : pwallet->GetKeys()) {
std::array<uint8_t, 20> address{};
std::copy(keyID.begin(), keyID.end(), address.begin());
Expand Down Expand Up @@ -682,7 +682,7 @@ UniValue utxostoaccount(const JSONRPCRequest& request) {
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[0].get_obj());

for (const auto& [to, amount] : msg.to) {
RejectEthAddress(to);
RejectErc55Address(to);
}

// encode
Expand Down Expand Up @@ -840,9 +840,9 @@ UniValue accounttoaccount(const JSONRPCRequest& request) {
msg.from = DecodeScript(request.params[0].get_str());

for (const auto& [to, amount] : msg.to) {
RejectEthAddress(to);
RejectErc55Address(to);
}
RejectEthAddress(msg.from);
RejectErc55Address(msg.from);

// encode
CDataStream markedMetadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
Expand Down Expand Up @@ -930,7 +930,7 @@ UniValue accounttoutxos(const JSONRPCRequest& request) {
// decode sender and recipients
CAccountToUtxosMessage msg{};
msg.from = DecodeScript(request.params[0].get_str());
RejectEthAddress(msg.from);
RejectErc55Address(msg.from);
const auto to = DecodeRecipients(pwallet->chain(), request.params[1]);
msg.balances = SumAllTransfers(to);
if (msg.balances.balances.empty()) {
Expand Down Expand Up @@ -1939,10 +1939,10 @@ UniValue sendtokenstoaddress(const JSONRPCRequest& request) {
}

for (const auto& [to, amount] : msg.to) {
RejectEthAddress(to);
RejectErc55Address(to);
}
for (const auto& [from, amount] : msg.from) {
RejectEthAddress(from);
RejectErc55Address(from);
}

// encode
Expand Down Expand Up @@ -1999,7 +1999,7 @@ UniValue transferdomain(const JSONRPCRequest& request) {
auto pwallet = GetWallet(request);
// TODO: Add support for non-JSON parameteric input that's human friendly and intuitive
RPCHelpMan{"transferdomain",
"Creates (and submits to local node and network) a tx to transfer balance from DFI/ETH address to DFI/ETH address.\n" +
"Creates (and submits to local node and network) a tx to transfer assets across domains. DVM to EVM/EVM to DVM, etc.\n" +
HelpRequiringPassphrase(pwallet) + "\n",
{
{"array", RPCArg::Type::ARR, RPCArg::Optional::NO, "A json array of src and dst json objects",
Expand Down Expand Up @@ -2083,7 +2083,7 @@ UniValue transferdomain(const JSONRPCRequest& request) {
const auto auth = GetScriptForDestination(WitnessV0KeyHash(key.GetID()));
auths.insert(auth);
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER,strprintf("Failed to get compressed address for Bech32 equivilent of Eth address"));
throw JSONRPCError(RPC_INVALID_PARAMETER,strprintf("Failed to get compressed address for Bech32 equivilent of ERC55 address"));
}
} else
throw JSONRPCError(RPC_INVALID_PARAMETER,strprintf("Invalid parameters, src argument \"domain\" must be either %d (DFI token to EVM) or %d (EVM to DFI token)", static_cast<uint8_t>(VMDomain::DVM), static_cast<uint8_t>(VMDomain::EVM)));
Expand Down Expand Up @@ -2435,7 +2435,7 @@ UniValue HandleSendDFIP2201BTCInput(const JSONRPCRequest& request, CWalletCoinsU
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
const auto script = GetScriptForDestination(dest);
RejectEthAddress(script);
RejectErc55Address(script);

CSmartContractMessage msg{};
msg.name = contractPair.first;
Expand Down Expand Up @@ -2577,7 +2577,7 @@ UniValue futureswap(const JSONRPCRequest& request) {
msg.owner = GetScriptForDestination(dest);
msg.source = DecodeAmount(pwallet->chain(), request.params[1], "");

RejectEthAddress(msg.owner);
RejectErc55Address(msg.owner);

if (!request.params[2].isNull()) {
DCT_ID destTokenID{};
Expand Down Expand Up @@ -2681,7 +2681,7 @@ UniValue withdrawfutureswap(const JSONRPCRequest& request) {
msg.destination = destTokenID.v;
}

RejectEthAddress(msg.owner);
RejectErc55Address(msg.owner);

// Encode
CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/rpc_evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ UniValue evmtx(const JSONRPCRequest &request) {
"Creates (and submits to local node and network) a tx to send DFI token to EVM address.\n" +
HelpRequiringPassphrase(pwallet) + "\n",
{
{"from", RPCArg::Type::STR, RPCArg::Optional::NO, "From Eth address"},
{"from", RPCArg::Type::STR, RPCArg::Optional::NO, "From ERC55 address"},
{"nonce", RPCArg::Type::NUM, RPCArg::Optional::NO, "Transaction nonce"},
{"gasPrice", RPCArg::Type::NUM, RPCArg::Optional::NO, "Gas Price in Gwei"},
{"gasLimit", RPCArg::Type::NUM, RPCArg::Optional::NO, "Gas limit"},
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/rpc_loan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ UniValue takeloan(const JSONRPCRequest& request) {
if (!metaObj["to"].isNull())
takeLoan.to = DecodeScript(metaObj["to"].getValStr());

RejectEthAddress(takeLoan.to);
RejectErc55Address(takeLoan.to);

if (!metaObj["amounts"].isNull())
takeLoan.amounts = DecodeAmounts(pwallet->chain(), metaObj["amounts"], "");
Expand Down Expand Up @@ -1267,7 +1267,7 @@ UniValue paybackloan(const JSONRPCRequest& request) {
} else
from = DecodeScript(metaObj["from"].getValStr());

RejectEthAddress(from);
RejectErc55Address(from);

if (!::IsMine(*pwallet, from))
throw JSONRPCError(RPC_INVALID_PARAMETER,
Expand Down
18 changes: 9 additions & 9 deletions src/masternodes/rpc_poolpair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ UniValue addpoolliquidity(const JSONRPCRequest &request) {
msg.shareAddress = DecodeScript(request.params[1].get_str());

for (const auto& [from, balance] : msg.from) {
RejectEthAddress(from);
RejectErc55Address(from);
}
RejectEthAddress(msg.shareAddress);
RejectErc55Address(msg.shareAddress);

// encode
CDataStream markedMetadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
Expand Down Expand Up @@ -500,7 +500,7 @@ UniValue removepoolliquidity(const JSONRPCRequest &request) {
msg.from = DecodeScript(from);
msg.amount = DecodeAmount(pwallet->chain(), amount, from);

RejectEthAddress(msg.from);
RejectErc55Address(msg.from);

// encode
CDataStream markedMetadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
Expand Down Expand Up @@ -641,7 +641,7 @@ UniValue createpoolpair(const JSONRPCRequest &request) {
if (!metadataObj["customRewards"].isNull()) {
rewards = DecodeAmounts(pwallet->chain(), metadataObj["customRewards"], "");
}
RejectEthAddress(ownerAddress);
RejectErc55Address(ownerAddress);

int targetHeight;
DCT_ID idtokenA, idtokenB;
Expand Down Expand Up @@ -821,7 +821,7 @@ UniValue updatepoolpair(const JSONRPCRequest &request) {
std::numeric_limits<CAmount>::max()));
}
}
RejectEthAddress(ownerAddress);
RejectErc55Address(ownerAddress);

const auto txVersion = GetTransactionVersion(targetHeight);
CMutableTransaction rawTx(txVersion);
Expand Down Expand Up @@ -939,8 +939,8 @@ UniValue poolswap(const JSONRPCRequest &request) {
CheckAndFillPoolSwapMessage(request, poolSwapMsg);
int targetHeight = chainHeight(*pwallet->chain().lock()) + 1;

RejectEthAddress(poolSwapMsg.from);
RejectEthAddress(poolSwapMsg.to);
RejectErc55Address(poolSwapMsg.from);
RejectErc55Address(poolSwapMsg.to);

CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
metadata << static_cast<unsigned char>(CustomTxType::PoolSwap);
Expand Down Expand Up @@ -1060,8 +1060,8 @@ UniValue compositeswap(const JSONRPCRequest &request) {
CPoolSwapMessage &poolSwapMsg = poolSwapMsgV2.swapInfo;
CheckAndFillPoolSwapMessage(request, poolSwapMsg);

RejectEthAddress(poolSwapMsg.from);
RejectEthAddress(poolSwapMsg.to);
RejectErc55Address(poolSwapMsg.from);
RejectErc55Address(poolSwapMsg.to);

{
LOCK(cs_main);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ UniValue creategovcfp(const JSONRPCRequest &request) {
pm.contextHash = contextHash;
pm.options = 0;

RejectEthAddress(pm.address);
RejectErc55Address(pm.address);

// encode
CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
Expand Down
12 changes: 6 additions & 6 deletions src/masternodes/rpc_vault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ UniValue createvault(const JSONRPCRequest& request) {
CVaultMessage vault;
vault.ownerAddress = DecodeScript(request.params[0].getValStr());

RejectEthAddress(vault.ownerAddress);
RejectErc55Address(vault.ownerAddress);

if (request.params.size() > 1) {
if (!request.params[1].isNull()) {
Expand Down Expand Up @@ -409,7 +409,7 @@ UniValue closevault(const JSONRPCRequest& request) {

msg.to = DecodeScript(request.params[1].getValStr());

RejectEthAddress(msg.to);
RejectErc55Address(msg.to);

CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
metadata << static_cast<unsigned char>(CustomTxType::CloseVault)
Expand Down Expand Up @@ -718,7 +718,7 @@ UniValue updatevault(const JSONRPCRequest& request) {
msg.ownerAddress = DecodeScript(ownerAddress);
}

RejectEthAddress(msg.ownerAddress);
RejectErc55Address(msg.ownerAddress);

if(!params["loanSchemeId"].isNull()){
auto loanschemeid = params["loanSchemeId"].getValStr();
Expand Down Expand Up @@ -808,7 +808,7 @@ UniValue deposittovault(const JSONRPCRequest& request) {
// decode vaultId
CVaultId vaultId = ParseHashV(request.params[0], "vaultId");
auto from = DecodeScript(request.params[1].get_str());
RejectEthAddress(from);
RejectErc55Address(from);
CTokenAmount amount = DecodeAmount(pwallet->chain(),request.params[2].get_str(), "amount");

CDepositToVaultMessage msg{vaultId, from, amount};
Expand Down Expand Up @@ -895,7 +895,7 @@ UniValue withdrawfromvault(const JSONRPCRequest& request) {
// decode vaultId
CVaultId vaultId = ParseHashV(request.params[0], "vaultId");
auto to = DecodeScript(request.params[1].get_str());
RejectEthAddress(to);
RejectErc55Address(to);
CTokenAmount amount = DecodeAmount(pwallet->chain(),request.params[2].get_str(), "amount");

CWithdrawFromVaultMessage msg{vaultId, to, amount};
Expand Down Expand Up @@ -1014,7 +1014,7 @@ UniValue placeauctionbid(const JSONRPCRequest& request) {
from = DecodeScript(fromStr);
}

RejectEthAddress(from);
RejectErc55Address(from);

CAuctionBidMessage msg{vaultId, index, from, amount};
CDataStream markedMetadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION);
Expand Down
9 changes: 4 additions & 5 deletions src/outputtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit";
static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32";
static const std::string OUTPUT_TYPE_STRING_ERC55 = "erc55";
static const std::string OUTPUT_TYPE_STRING_ETH = "eth";

bool ParseOutputType(const std::string& type, OutputType& output_type)
{
Expand All @@ -31,8 +30,8 @@ bool ParseOutputType(const std::string& type, OutputType& output_type)
} else if (type == OUTPUT_TYPE_STRING_BECH32) {
output_type = OutputType::BECH32;
return true;
} else if (type == OUTPUT_TYPE_STRING_ERC55 || type == OUTPUT_TYPE_STRING_ETH) {
output_type = OutputType::ETH;
} else if (type == OUTPUT_TYPE_STRING_ERC55) {
output_type = OutputType::ERC55;
return true;
}
return false;
Expand All @@ -44,7 +43,7 @@ const std::string& FormatOutputType(OutputType type)
case OutputType::LEGACY: return OUTPUT_TYPE_STRING_LEGACY;
case OutputType::P2SH_SEGWIT: return OUTPUT_TYPE_STRING_P2SH_SEGWIT;
case OutputType::BECH32: return OUTPUT_TYPE_STRING_BECH32;
case OutputType::ETH: return OUTPUT_TYPE_STRING_ETH;
case OutputType::ERC55: return OUTPUT_TYPE_STRING_ERC55;
default: assert(false);
}
}
Expand All @@ -64,7 +63,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
return witdest;
}
}
case OutputType::ETH: {
case OutputType::ERC55: {
CPubKey pubkeyCopy = key;
if (pubkeyCopy.IsCompressed()) {
pubkeyCopy.Decompress();
Expand Down
2 changes: 1 addition & 1 deletion src/outputtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum class OutputType {
LEGACY,
P2SH_SEGWIT,
BECH32,
ETH,
ERC55,

/**
* Special output type for change outputs only. Automatically choose type
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/rawtransaction_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ CScript DecodeScript(std::string const& str)
return GetScriptForDestination(dest);
}

void RejectEthAddress(const CScript &address) {
void RejectErc55Address(const CScript &address) {
CTxDestination dest;
if (ExtractDestination(address, dest) && dest.index() == WitV16KeyEthHashType) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Eth type addresses are not valid");
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "ERC55 addresses not supported");
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
}
CScript scriptPubKey = GetScriptForDestination(destination);

RejectEthAddress(scriptPubKey);
RejectErc55Address(scriptPubKey);

auto amounts = DecodeAmounts(chain, outputs[name_], name_);
for (auto const & kv : amounts.balances) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ResVal<std::pair<CAmount, std::string>> ParseTokenAmount(std::string const & tok
ResVal<CTokenAmount> GuessTokenAmount(interfaces::Chain const & chain,std::string const & tokenAmount);

CScript DecodeScript(std::string const& str);
void RejectEthAddress(const CScript &address);
void RejectErc55Address(const CScript &address);
CTokenAmount DecodeAmount(interfaces::Chain const & chain, UniValue const& amountUni, std::string const& name);
CBalances DecodeAmounts(interfaces::Chain const & chain, UniValue const& amountsUni, std::string const& name);
CAccounts DecodeRecipients(interfaces::Chain const & chain, UniValue const& sendTo);
Expand Down
2 changes: 1 addition & 1 deletion src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ bool static CheckPubKeyEncoding(const valtype &vchPubKey, unsigned int flags, co
if ((flags & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE) != 0 && sigversion == SigVersion::WITNESS_V0 && !IsCompressedPubKey(vchPubKey)) {
return set_error(serror, SCRIPT_ERR_WITNESS_PUBKEYTYPE);
}
// Only uncompressed keys are accepted in Eth addresses
// Only uncompressed keys are accepted in ERC55 addresses
if ((flags & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE) != 0 && sigversion == SigVersion::WITNESS_V16 && IsCompressedPubKey(vchPubKey)) {
return set_error(serror, SCRIPT_ERR_WITNESS_ETHKEYTYPE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/script/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct WitnessUnknown {
* * WitnessV0ScriptHash: TX_WITNESS_V0_SCRIPTHASH destination (P2WSH)
* * WitnessV0KeyHash: TX_WITNESS_V0_KEYHASH destination (P2WPKH)
* * WitnessUnknown: TX_WITNESS_UNKNOWN destination (P2W???)
* * WitnessV16EthHash: Eth address type. Not a valid destination, here for address support anly.
* * WitnessV16EthHash: ERC55 address type. Not a valid destination, here for address support anly.
* A CTxDestination is the internal data type encoded in a DFI address
*/
using CTxDestination = std::variant<CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown, WitnessV16EthHash>;
Expand Down
Loading

0 comments on commit e9a6ccb

Please sign in to comment.