Skip to content

Commit

Permalink
Merge branch 'master' into vladik5
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Nov 6, 2023
2 parents 32d33c7 + 61e220f commit f7d29ea
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 73 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/ethash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ See [ethash.hpp] for list of exported function and documentation.

## Optimizations

This section decscribes the optimizations, modification and tweaks applied
This section describes the optimizations, modifications and tweaks applied
in this library in relation to [Ethash reference implementation].

The library contains a set of micro-benchmarks. Build and run `bench` tool.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BEAM is a Confidential Cryptocurrency and DeFi Platform
* Allows creation of new [Confidential Assets](https://beam.mw/en/docs/ecosystem/#tokens-aka-beam-confidential-assets) (part of the protocol, no contracts required)
* Supports privacy preserving [Smart Contracts](https://github.com/BeamMW/shader-sdk/wiki/Beam-Smart-Contracts) via bespoke Beam Virtual Machine [spec](https://github.com/BeamMW/shader-sdk/wiki/BVM-functions-for-shaders) based on WASM technology
* Beautiful and usable wallets for all platforms (Win, Mac, Linux, iOS, Android, Web)
* Bridges with Ethereum blockhain (supporting USDT, DAI, WBTC and ETH)
* Bridges with Ethereum blockchain (supporting USDT, DAI, WBTC and ETH)
* Fully decentralized Atomic Swaps (with BTC, LTC and ETH) with an in-wallet marketplace
* Rich DeFi ecosystem including DEX, Confidential Stable Coin, Anonymous Name Service, NFT Gallery and more...

Expand Down
6 changes: 3 additions & 3 deletions android/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ JNIEXPORT jobject JNICALL BEAM_JAVA_WALLET_INTERFACE(getTransactionParameters)(J
uint64_t bAmount = amount;
uint32_t bAsset = assetId;

walletModel->getAsync()->generateToken(TokenType::Offline, bAmount, beam::Asset::ID(bAsset), std::string(BEAM_LIB_VERSION), [&] (std::string token)
walletModel->getAsync()->generateToken(TokenType::Offline, bAmount, beam::Asset::ID(bAsset), std::string(BEAM_LIB_VERSION), false, [&] (std::string token)
{
JNIEnv* env = Android_JNI_getEnv();
jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onOfflineAddress", "(Ljava/lang/String;)V");
Expand All @@ -313,7 +313,7 @@ JNIEXPORT jobject JNICALL BEAM_JAVA_WALLET_INTERFACE(getTransactionParameters)(J
uint64_t bAmount = amount;
uint32_t bAsset = assetId;

walletModel->getAsync()->generateToken(TokenType::RegularNewStyle, bAmount, beam::Asset::ID(bAsset), std::string(BEAM_LIB_VERSION), [&] (std::string token)
walletModel->getAsync()->generateToken(TokenType::RegularNewStyle, bAmount, beam::Asset::ID(bAsset), std::string(BEAM_LIB_VERSION), false, [&] (std::string token)
{
JNIEnv* env = Android_JNI_getEnv();
jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onRegularAddress", "(Ljava/lang/String;)V");
Expand All @@ -330,7 +330,7 @@ JNIEXPORT jobject JNICALL BEAM_JAVA_WALLET_INTERFACE(getTransactionParameters)(J
uint64_t bAmount = amount;
uint32_t bAsset = assetId;

walletModel->getAsync()->generateToken(TokenType::MaxPrivacy, bAmount, beam::Asset::ID(bAsset), std::string(BEAM_LIB_VERSION), [&] (std::string token)
walletModel->getAsync()->generateToken(TokenType::MaxPrivacy, bAmount, beam::Asset::ID(bAsset), std::string(BEAM_LIB_VERSION), false, [&] (std::string token)
{
JNIEnv* env = Android_JNI_getEnv();
jmethodID callback = env->GetStaticMethodID(WalletListenerClass, "onMaxPrivacyAddress", "(Ljava/lang/String;)V");
Expand Down
153 changes: 102 additions & 51 deletions bvm/Shaders/Explorer/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ struct ParserContext
}
};


void OnDaoAccumulator_UserWithdraw(uint8_t nType);
void OnState_DaoAccumulator_Pool(DaoAccumulator::Pool&, const char* szName);
void OnState_DaoAccumulator_Users(DaoAccumulator::Pool&, uint8_t type, const char* szName);

};

bool ParserContext::Parse()
Expand Down Expand Up @@ -2388,6 +2393,38 @@ void ParserContext::OnState_DEX(uint32_t /* iVer */)

}

void OnDaoAccumulator_PoolType(uint8_t nType)
{
static const char s_szName[] = "Pool";
switch (nType)
{
case DaoAccumulator::Method::UserLock::Type::BeamX_PrePhase:
Env::DocAddText(s_szName, "Beam-BeamX pre-phase");
break;

case DaoAccumulator::Method::UserLock::Type::BeamX:
Env::DocAddText(s_szName, "Beam-BeamX");
break;

case DaoAccumulator::Method::UserLock::Type::Nph:
Env::DocAddText(s_szName, "Beam-Nph");
break;
}
}

void ParserContext::OnDaoAccumulator_UserWithdraw(uint8_t nType)
{
auto pArg = get_ArgsAs<DaoAccumulator::Method::UserWithdraw_Base>();
if (pArg)
{
OnMethod("Withdraw");
GroupArgs gr;

OnDaoAccumulator_PoolType(nType);

DocAddPk("pk", pArg->m_pkUser);
}
}

void ParserContext::OnMethod_DaoAccumulator(uint32_t /* iVer */)
{
Expand Down Expand Up @@ -2434,23 +2471,70 @@ void ParserContext::OnMethod_DaoAccumulator(uint32_t /* iVer */)
{
OnMethod("Lock");
GroupArgs gr;
OnDaoAccumulator_PoolType(pArg->m_PoolType);
DocAddPk("pk", pArg->m_pkUser);
DocAddHeight("hEnd", pArg->m_hEnd);
}
}
break;

case DaoAccumulator::Method::UserUpdate::s_iMethod:
case DaoAccumulator::Method::UserWithdraw_FromBeamNph::s_iMethod:
OnDaoAccumulator_UserWithdraw(DaoAccumulator::Method::UserLock::Type::Nph);
break;

case DaoAccumulator::Method::UserWithdraw_FromBeamBeamX::s_iMethod:
OnDaoAccumulator_UserWithdraw(DaoAccumulator::Method::UserLock::Type::BeamX);
break;
}
}

void ParserContext::OnState_DaoAccumulator_Pool(DaoAccumulator::Pool& p, const char* szName)
{
Env::DocGroup gr(szName);

p.Update(Env::get_Height());

DocAddAmount("Reward remaining", p.m_AmountRemaining);
Env::DocAddNum("Farming duration remaining", p.m_hRemaining);
}

void ParserContext::OnState_DaoAccumulator_Users(DaoAccumulator::Pool& p, uint8_t type, const char* szName)
{
Env::DocGroup gr2(szName);
DocSetType("table");
Env::DocArray gr3("value");

{
auto pArg = get_ArgsAs<DaoAccumulator::Method::UserUpdate>();
if (pArg)
{
OnMethod("User update");
GroupArgs gr;
DocAddPk("pk", pArg->m_pkUser);
}
Env::DocArray gr4("");
DocAddTableHeader("LP-Tokens");
DocAddTableHeader("Locked until");
DocAddTableHeader("Reward");
DocAddTableHeader("Key");
}
break;

Env::Key_T<DaoAccumulator::User::KeyBase> k0, k1;
k0.m_KeyInContract.m_Tag = type;
k1.m_KeyInContract.m_Tag = type;
_POD_(k0.m_Prefix.m_Cid) = m_Cid;
_POD_(k1.m_Prefix.m_Cid) = m_Cid;
_POD_(k0.m_KeyInContract.m_pk).SetZero();
_POD_(k1.m_KeyInContract.m_pk).SetObject(0xff);

for (Env::VarReader r(k0, k1); ; )
{
DaoAccumulator::User u;
if (!r.MoveNext_T(k0, u))
break;

Env::DocArray gr4("");

DocAddAmount("", u.m_LpToken);
DocAddHeight("", u.m_hEnd);

u.m_EarnedBeamX += p.Remove(u.m_PoolUser);
DocAddAmount("", u.m_EarnedBeamX);

DocAddPk("", k0.m_KeyInContract.m_pk);
}
}

Expand All @@ -2473,52 +2557,19 @@ void ParserContext::OnState_DaoAccumulator(uint32_t /* iVer */)
{
DocAddAid("LP-token", s.m_aidLpToken);

s.m_Pool.Update(Env::get_Height());

DocAddAmount("Reward remaining", s.m_Pool.m_AmountRemaining);
Env::DocAddNum("Farming duration remaining", s.m_Pool.m_hRemaining);
OnState_DaoAccumulator_Pool(s.m_Pool, "Pool Beam/BeamX");
}

{
Env::DocGroup gr2("Users");
DocSetType("table");
Env::DocArray gr3("value");

{
Env::DocArray gr4("");
DocAddTableHeader("LP-Tokens");
DocAddTableHeader("Locked until");
DocAddTableHeader("Reward");
DocAddTableHeader("Key");
}

Env::Key_T<DaoAccumulator::User::Key> k0, k1;
_POD_(k0.m_Prefix.m_Cid) = m_Cid;
_POD_(k1.m_Prefix.m_Cid) = m_Cid;
_POD_(k0.m_KeyInContract.m_pk).SetZero();
_POD_(k1.m_KeyInContract.m_pk).SetObject(0xff);

for (Env::VarReader r(k0, k1); ; )
{
DaoAccumulator::User u;
if (!r.MoveNext_T(k0, u))
break;

Env::DocArray gr4("");

DocAddAmount("", u.m_LpToken);
DocAddHeight("", u.m_hEnd);

if (s.m_aidLpToken)
u.m_EarnedBeamX += s.m_Pool.Remove(u.m_PoolUser);

DocAddAmount("", u.m_EarnedBeamX);
DaoAccumulator::Pool p_Nph;
k.m_KeyInContract = DaoAccumulator::Tags::s_PoolBeamNph;

DocAddPk("", k0.m_KeyInContract.m_pk);
}

}
if (Env::VarReader::Read_T(k, p_Nph))
OnState_DaoAccumulator_Pool(p_Nph, "Pool Beam/Nph");
else
_POD_(p_Nph).SetZero();

OnState_DaoAccumulator_Users(s.m_Pool, DaoAccumulator::Tags::s_User, "Beam/BeamX users");
OnState_DaoAccumulator_Users(p_Nph, DaoAccumulator::Tags::s_UserBeamNph, "Beam/Nph users");
}


Expand Down
Binary file modified bvm/Shaders/Explorer/Parser.wasm
Binary file not shown.
24 changes: 19 additions & 5 deletions wallet/client/wallet_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ struct WalletModelBridge : public Bridge<IWalletModelAsync>
call_async((MethodType)&IWalletModelAsync::generateNewAddress, std::move(callback));
}

void generateToken(wallet::TokenType type, Amount amount, Asset::ID aid, std::string sVer, AsyncCallback<std::string&&>&& callback) override
void generateToken(wallet::TokenType type, Amount amount, Asset::ID aid, std::string sVer, bool newAddress, AsyncCallback<std::string&&>&& callback) override
{
typedef void(IWalletModelAsync::* MethodType)(wallet::TokenType, Amount, Asset::ID, std::string, AsyncCallback<std::string&&>&&);
call_async((MethodType)&IWalletModelAsync::generateToken, type, amount, aid, std::move(sVer), std::move(callback));
typedef void(IWalletModelAsync::* MethodType)(wallet::TokenType, Amount, Asset::ID, std::string, bool, AsyncCallback<std::string&&>&&);
call_async((MethodType)&IWalletModelAsync::generateToken, type, amount, aid, std::move(sVer), newAddress, std::move(callback));
}

void deleteAddress(const WalletID& addr) override
Expand Down Expand Up @@ -1687,13 +1687,21 @@ namespace beam::wallet
}
}

void WalletClient::generateToken(TokenType type, Amount amount, Asset::ID aid, std::string sVer, AsyncCallback<std::string&&>&& callback)
void WalletClient::generateToken(TokenType type, Amount amount, Asset::ID aid, std::string sVer, bool newAddress, AsyncCallback<std::string&&>&& callback)
{
std::string sToken;
try
{
WalletAddress wa;
m_walletDB->getDefaultAddressAlways(wa);
if (newAddress)
{
m_walletDB->createAddress(wa);
wa.setExpirationStatus(WalletAddress::ExpirationStatus::Auto);
}
else
{
m_walletDB->getDefaultAddressAlways(wa);
}

switch (type)
{
Expand All @@ -1708,6 +1716,12 @@ namespace beam::wallet
default:
sToken = GenerateToken(type, wa, m_walletDB);
}

if (newAddress)
{
wa.m_Token = sToken;
m_walletDB->saveAddress(wa);
}
}
catch (const std::exception& e)
{
Expand Down
2 changes: 1 addition & 1 deletion wallet/client/wallet_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ namespace beam::wallet
void saveAddress(const WalletAddress& address) override;
void generateNewAddress() override;
void generateNewAddress(AsyncCallback<const WalletAddress&>&& callback) override;
void generateToken(TokenType, Amount, Asset::ID, std::string sVer, AsyncCallback<std::string&&>&& callback) override;
void generateToken(TokenType, Amount, Asset::ID, std::string sVer, bool newAddress, AsyncCallback<std::string&&>&& callback) override;
void deleteAddress(const WalletID& addr) override;
void updateAddress(const WalletID& addr, const std::string& name, WalletAddress::ExpirationStatus expirationStatus) override;
void updateAddress(const WalletID& addr, const std::string& name, beam::Timestamp expirationTime) override;
Expand Down
2 changes: 1 addition & 1 deletion wallet/client/wallet_model_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace beam::wallet
virtual void saveAddress(const WalletAddress& address) = 0;
virtual void generateNewAddress() = 0;
virtual void generateNewAddress(AsyncCallback<const WalletAddress&>&& callback) = 0;
virtual void generateToken(TokenType, Amount, Asset::ID, std::string sVer, AsyncCallback<std::string&&>&& callback) = 0;
virtual void generateToken(TokenType, Amount, Asset::ID, std::string sVer, bool newAddress, AsyncCallback<std::string&&>&& callback) = 0;

#ifdef BEAM_ATOMIC_SWAP_SUPPORT
virtual void loadSwapParams() = 0;
Expand Down
8 changes: 0 additions & 8 deletions wallet/core/default_peers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,8 @@ namespace beam
case Rules::Network::mainnet:
{
static const char* psz[] = {
"ap-nodes.mainnet.beam.mw:8100",
"eu-nodes.mainnet.beam.mw:8100",
"us-nodes.mainnet.beam.mw:8100",
"ap-hk-nodes.mainnet.beam.mw:8100",
"45.63.100.240:10127",
"usa.raskul.com:10174",
"canada.raskul.com:10174",
"japan.raskul.com:10127",
"india.raskul.com:10127",
"oz.raskul.com:10127",
};
Arr2Vec(result, psz, _countof(psz));
}
Expand Down
4 changes: 2 additions & 2 deletions wasmclient/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Overview

WASM wallet client is a thin wrapper around Beam client library build into WASM using Emscripten toolchain. This wrapper allows to run BEAM wallet inside any browser supporting WebAssembly and it provides the regular [BEAM wallet API](Beam-wallet-protocol-API) to communicated with it from external(javascript) code.
WASM wallet client is a thin wrapper around Beam client library build into WASM using Emscripten toolchain. This wrapper allows to run BEAM wallet inside any browser supporting WebAssembly and it provides the regular [BEAM wallet API](Beam-wallet-protocol-API) to communicate with it from external(javascript) code.

Please, look at [documentation](https://github.com/BeamMW/beam/wiki/WASM-wallet-client) to start use it
Please, look at [documentation](https://github.com/BeamMW/beam/wiki/WASM-wallet-client) to start use it

0 comments on commit f7d29ea

Please sign in to comment.