Skip to content
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

Polygon network for UD wallet address #13085

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/brave_wallet/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ static_library("browser") {
"tx_service.h",
"tx_state_manager.cc",
"tx_state_manager.h",
"unstoppable_domains_multichain_calls.cc",
"unstoppable_domains_multichain_calls.h",
"wallet_data_files_installer.cc",
"wallet_data_files_installer.h",
]
Expand Down
20 changes: 17 additions & 3 deletions components/brave_wallet/browser/brave_wallet_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/environment.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
Expand Down Expand Up @@ -235,12 +236,14 @@ const base::flat_map<std::string, std::string> kFilecoinSubdomains = {
{brave_wallet::mojom::kFilecoinMainnet, "mainnet"},
{brave_wallet::mojom::kFilecoinTestnet, "testnet"}};

// Addesses taken from https://docs.unstoppabledomains.com/developer-toolkit/
// smart-contracts/uns-smart-contracts/#proxyreader
const base::flat_map<std::string, std::string>
kUnstoppableDomainsProxyReaderContractAddressMap = {
{brave_wallet::mojom::kMainnetChainId,
"0xa6E7cEf2EDDEA66352Fd68E5915b60BDbb7309f5"},
{brave_wallet::mojom::kRinkebyChainId,
"0x3A2e74CF832cbA3d77E72708d55370119E4323a6"}};
"0xc3C2BAB5e3e52DBF311b2aAcEf2e40344f19494E"},
{brave_wallet::mojom::kPolygonMainnetChainId,
"0xA3f32c8cd786dc089Bd1fC175F2707223aeE5d00"}};
yrliou marked this conversation as resolved.
Show resolved Hide resolved

const base::flat_map<std::string, std::string> kEnsRegistryContractAddressMap =
{{brave_wallet::mojom::kMainnetChainId,
Expand Down Expand Up @@ -907,6 +910,17 @@ std::string GetDefaultBaseCryptocurrency(PrefService* prefs) {
return prefs->GetString(kDefaultBaseCryptocurrency);
}

GURL GetUnstoppableDomainsRpcUrl(const std::string& chain_id) {
yrliou marked this conversation as resolved.
Show resolved Hide resolved
if (chain_id == brave_wallet::mojom::kPolygonMainnetChainId)
return GURL("https://polygon-rpc.com");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be changed to brave.com subdomain in nearest future


if (chain_id == brave_wallet::mojom::kMainnetChainId)
return GURL(GetInfuraURLForKnownChainId(chain_id));

NOTREACHED();
return GURL();
}

std::string GetUnstoppableDomainsProxyReaderContractAddress(
const std::string& chain_id) {
if (kUnstoppableDomainsProxyReaderContractAddressMap.contains(chain_id))
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet/browser/brave_wallet_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ std::vector<std::string> GetAllKnownSolNetworkIds();
std::vector<std::string> GetAllKnownFilNetworkIds();
std::string GetKnownEthNetworkId(const std::string& chain_id);

GURL GetUnstoppableDomainsRpcUrl(const std::string& chain_id);
std::string GetUnstoppableDomainsProxyReaderContractAddress(
const std::string& chain_id);
std::string GetEnsRegistryContractAddress(const std::string& chain_id);
Expand Down
29 changes: 17 additions & 12 deletions components/brave_wallet/browser/eth_data_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,51 +218,56 @@ bool SupportsInterface(const std::string& interface_id, std::string* data) {

namespace unstoppable_domains {

bool GetMany(const std::vector<std::string>& keys,
const std::string& domain,
std::string* data) {
absl::optional<std::string> GetMany(const std::vector<std::string>& keys,
const std::string& domain) {
const std::string function_hash =
GetFunctionHash("getMany(string[],uint256)");

std::string offset_for_array;
if (!PadHexEncodedParameter(Uint256ValueToHex(64), &offset_for_array)) {
return false;
return absl::nullopt;
}

std::string tokenID = Namehash(domain);

std::string encoded_keys;
if (!EncodeStringArray(keys, &encoded_keys)) {
return false;
return absl::nullopt;
}

std::string data;
std::vector<std::string> hex_strings = {function_hash, offset_for_array,
tokenID, encoded_keys};
if (!ConcatHexStrings(hex_strings, data)) {
return false;
if (!ConcatHexStrings(hex_strings, &data)) {
return absl::nullopt;
}

return true;
return data;
}

bool Get(const std::string& key, const std::string& domain, std::string* data) {
absl::optional<std::string> Get(const std::string& key,
const std::string& domain) {
const std::string function_hash = GetFunctionHash("get(string,uint256)");

std::string offset_for_key;
if (!PadHexEncodedParameter(Uint256ValueToHex(64), &offset_for_key)) {
return false;
return absl::nullopt;
}

std::string tokenID = Namehash(domain);

std::string encoded_key;
if (!EncodeString(key, &encoded_key)) {
return false;
return absl::nullopt;
}

std::string data;
std::vector<std::string> hex_strings = {function_hash, offset_for_key,
tokenID, encoded_key};
return ConcatHexStrings(hex_strings, data);
if (!ConcatHexStrings(hex_strings, &data))
return absl::nullopt;

return data;
}

} // namespace unstoppable_domains
Expand Down
9 changes: 5 additions & 4 deletions components/brave_wallet/browser/eth_data_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>
#include "base/values.h"
#include "brave/components/brave_wallet/common/brave_wallet_types.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace brave_wallet {

Expand Down Expand Up @@ -70,12 +71,12 @@ bool SupportsInterface(const std::string& interface_id, std::string* data);
namespace unstoppable_domains {

// Get mutiple record values mapped with keys of the target domain.
bool GetMany(const std::vector<std::string>& keys,
const std::string& domain,
std::string* data);
absl::optional<std::string> GetMany(const std::vector<std::string>& keys,
const std::string& domain);

// Get the value of the key for the target domain.
bool Get(const std::string& key, const std::string& domain, std::string* data);
absl::optional<std::string> Get(const std::string& key,
const std::string& domain);

} // namespace unstoppable_domains

Expand Down
11 changes: 6 additions & 5 deletions components/brave_wallet/browser/eth_data_builder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ TEST(EthCallDataBuilderTest, SupportsInterface) {
namespace unstoppable_domains {

TEST(EthCallDataBuilderTest, GetMany) {
std::string data;
std::vector<std::string> keys = {"crypto.ETH.address"};
EXPECT_TRUE(GetMany(keys, "brave.crypto", &data));
auto data = GetMany(keys, "brave.crypto");
EXPECT_TRUE(data);
EXPECT_EQ(data,
"0x1bd8cc1a"
// Offset to the start of keys array.
Expand All @@ -163,7 +163,8 @@ TEST(EthCallDataBuilderTest, GetMany) {

keys = {"dweb.ipfs.hash", "ipfs.html.value", "browser.redirect_url",
"ipfs.redirect_domain.value"};
EXPECT_TRUE(GetMany(keys, "brave.crypto", &data));
data = GetMany(keys, "brave.crypto");
EXPECT_TRUE(data);
EXPECT_EQ(data,
"0x1bd8cc1a"
// Offset to the start of keys array.
Expand Down Expand Up @@ -196,8 +197,8 @@ TEST(EthCallDataBuilderTest, GetMany) {
}

TEST(EthCallDataBuilderTest, Get) {
std::string data;
EXPECT_TRUE(Get("crypto.ETH.address", "brave.crypto", &data));
auto data = Get("crypto.ETH.address", "brave.crypto");
EXPECT_TRUE(data);
EXPECT_EQ(data,
"0x1be5e7ed"
"0000000000000000000000000000000000000000000000000000000000000040"
Expand Down
15 changes: 9 additions & 6 deletions components/brave_wallet/browser/eth_response_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,19 @@ bool ParseUnstoppableDomainsProxyReaderGetMany(
return brave_wallet::DecodeStringArray(result.substr(offset), values);
}

bool ParseUnstoppableDomainsProxyReaderGet(const std::string& json,
std::string* value) {
DCHECK(value);

absl::optional<std::string> ParseUnstoppableDomainsProxyReaderGet(
const std::string& json) {
std::string result;
if (!ParseSingleStringResult(json, &result))
return false;
return absl::nullopt;

size_t offset = 2 /* len of "0x" */ + 64 /* len of offset to array */;
return brave_wallet::DecodeString(offset, result, value);
std::string value;
if (!brave_wallet::DecodeString(offset, result, &value)) {
return absl::nullopt;
}

return value;
}

} // namespace eth
Expand Down
4 changes: 2 additions & 2 deletions components/brave_wallet/browser/eth_response_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ bool ParseUnstoppableDomainsProxyReaderGetMany(
const std::string& json,
std::vector<std::string>* values);

bool ParseUnstoppableDomainsProxyReaderGet(const std::string& json,
std::string* value);
absl::optional<std::string> ParseUnstoppableDomainsProxyReaderGet(
const std::string& json);

} // namespace eth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,15 @@ TEST(EthResponseParserUnitTest, ParseUnstoppableDomainsProxyReaderGet) {
// Encoded string of 0x8aaD44321A86b170879d7A244c1e8d360c99DdA8
"3078386161443434333231413836623137303837396437413234346331653864"
"3336306339394464413800000000000000000000000000000000000000000000\"}";
std::string value;
EXPECT_TRUE(ParseUnstoppableDomainsProxyReaderGet(json, &value));
auto value = ParseUnstoppableDomainsProxyReaderGet(json);
EXPECT_TRUE(value);
EXPECT_EQ(value, "0x8aaD44321A86b170879d7A244c1e8d360c99DdA8");

value = "";
json =
"{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":"
"\"0x000000000000000000000000000000000000000000000000000000000000002000";
EXPECT_FALSE(ParseUnstoppableDomainsProxyReaderGet(json, &value));
EXPECT_TRUE(value.empty());
value = ParseUnstoppableDomainsProxyReaderGet(json);
EXPECT_FALSE(value);
}

TEST(EthResponseParserUnitTest, ParseEthGetFeeHistory) {
Expand Down
Loading