Skip to content

Commit 9099de9

Browse files
committed
Merge remote-tracking branch 'remotes/origin/eager_electron_5.2RC_API' into mainnet
2 parents 121e840 + c59b4d4 commit 9099de9

24 files changed

+638
-250
lines changed

android/wallet_model.cpp

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,6 @@ namespace
5858
return addr;
5959
}
6060

61-
std::string getAddressFrom(TxDescription m_tx)
62-
{
63-
if (m_tx.m_txType == wallet::TxType::PushTransaction && !m_tx.m_sender){
64-
return m_tx.getSenderIdentity();
65-
}
66-
return to_string(m_tx.m_sender ? m_tx.m_myId : m_tx.m_peerId);
67-
}
68-
69-
std::string getAddressTo(TxDescription m_tx)
70-
{
71-
if (m_tx.m_sender)
72-
{
73-
auto token = m_tx.getToken();
74-
if (token.length() == 0) {
75-
return to_string(m_tx.m_myId);
76-
}
77-
auto params = beam::wallet::ParseParameters(token);
78-
if (auto peerIdentity = params->GetParameter<WalletID>(TxParameterID::PeerID); peerIdentity)
79-
{
80-
auto s = std::to_string(*peerIdentity);
81-
return s;
82-
}
83-
return token;
84-
}
85-
return to_string(m_tx.m_myId);
86-
}
87-
8861
jobject fillTransactionData(JNIEnv* env, const TxDescription& txDescription)
8962
{
9063
jobject tx = env->AllocObject(TxDescriptionClass);
@@ -113,8 +86,8 @@ namespace
11386
setStringField(env, TxDescriptionClass, tx, "senderIdentity", txDescription.getSenderIdentity());
11487
setStringField(env, TxDescriptionClass, tx, "receiverIdentity", txDescription.getReceiverIdentity());
11588

116-
setStringField(env, TxDescriptionClass, tx, "receiverAddress", getAddressTo(txDescription));
117-
setStringField(env, TxDescriptionClass, tx, "senderAddress", getAddressFrom(txDescription));
89+
setStringField(env, TxDescriptionClass, tx, "receiverAddress", txDescription.getAddressTo());
90+
setStringField(env, TxDescriptionClass, tx, "senderAddress", txDescription.getAddressFrom());
11891

11992
if(txDescription.m_txType == wallet::TxType::PushTransaction) {
12093
auto token = txDescription.getToken();

explorer/adapter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ class Adapter : public Node::IObserver, public IAdapter {
257257
std::make_shared<wallet::OfferBoardProtocolHandler>(_walletDB->get_SbbsKdf());
258258
_offersBulletinBoard = std::make_shared<wallet::SwapOffersBoard>(
259259
*_broadcastRouter, *_offerBoardProtocolHandler, _walletDB);
260+
_walletDbSubscriber = std::make_unique<WalletDbSubscriber>(
261+
static_cast<wallet::IWalletDbObserver*>(_offersBulletinBoard.get()), _walletDB);
260262
#endif // BEAM_ATOMIC_SWAP_SUPPORT
261263
}
262264

@@ -925,6 +927,8 @@ class Adapter : public Node::IObserver, public IAdapter {
925927
#ifdef BEAM_ATOMIC_SWAP_SUPPORT
926928
std::shared_ptr<wallet::OfferBoardProtocolHandler> _offerBoardProtocolHandler;
927929
wallet::SwapOffersBoard::Ptr _offersBulletinBoard;
930+
using WalletDbSubscriber = wallet::ScopedSubscriber<wallet::IWalletDbObserver, wallet::IWalletDB>;
931+
std::unique_ptr<WalletDbSubscriber> _walletDbSubscriber;
928932
#endif // BEAM_ATOMIC_SWAP_SUPPORT
929933
};
930934

utility/cli/options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ namespace beam
319319
const char* MAX_PRIVACY_ADDRESS = "max_privacy";
320320
const char* OFFLINE_ADDRESS = "offline";
321321
const char* PUBLIC_OFFLINE = "public_offline";
322+
const char* ENABLE_LELANTUS = "enable_lelantus";
322323
}
323324

324325

utility/cli/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ namespace beam
220220
extern const char* MAX_PRIVACY_ADDRESS;
221221
extern const char* OFFLINE_ADDRESS;
222222
extern const char* PUBLIC_OFFLINE;
223+
extern const char* ENABLE_LELANTUS;
223224
}
224225

225226
enum OptionsFlag : int

utility/io/timer.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,57 @@ void Timer::cancel() {
6262
}
6363

6464

65-
65+
IdleEvt::~IdleEvt()
66+
{
67+
if (m_pHandle)
68+
{
69+
m_pHandle->CancelSafe();
70+
uv_close(reinterpret_cast<uv_handle_t*>(&Cast::Down<uv_idle_t>(*m_pHandle)), Handle::OnClosed);
71+
}
72+
}
6673

6774
void IdleEvt::cancel()
6875
{
69-
if (m_Set)
76+
if (m_pHandle)
77+
m_pHandle->CancelSafe();
78+
}
79+
80+
void IdleEvt::start()
81+
{
82+
if (m_pHandle)
83+
{
84+
if (m_pHandle->m_pThis)
85+
return; // already set
86+
}
87+
else
7088
{
71-
m_Set = false;
72-
uv_idle_stop(&m_Handle);
73-
uv_close(reinterpret_cast<uv_handle_t*>(&Cast::Down<uv_idle_t>(m_Handle)), nullptr);
89+
m_pHandle = new Handle;
90+
uv_idle_init(&Reactor::get_Current().get_UvLoop(), m_pHandle);
7491
}
92+
93+
m_pHandle->m_pThis = this;
94+
uv_idle_start(m_pHandle, Handle::OnSchedule);
7595
}
7696

77-
void IdleEvt::start()
97+
void IdleEvt::Handle::CancelSafe()
7898
{
79-
if (!m_Set)
99+
if (m_pThis)
80100
{
81-
m_Set = true;
82-
uv_idle_init(&Reactor::get_Current().get_UvLoop(), &m_Handle);
83-
uv_idle_start(&m_Handle, Handle::CallbackRaw);
101+
m_pThis = nullptr;
102+
uv_idle_stop(this);
84103
}
85104
}
86105

87-
void IdleEvt::Handle::CallbackRaw(uv_idle_t* p)
106+
void IdleEvt::Handle::OnClosed(uv_handle_t* p)
107+
{
108+
delete Cast::Up<Handle>(reinterpret_cast<uv_idle_t*>(p));
109+
}
110+
111+
void IdleEvt::Handle::OnSchedule(uv_idle_t* p)
88112
{
89-
static_cast<Handle*>(p)->get_ParentObj().OnSchedule();
113+
IdleEvt* pThis = Cast::Up<Handle>(p)->m_pThis;
114+
assert(pThis);
115+
pThis->OnSchedule();
90116
}
91117

92118

utility/io/timer.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Timer : protected Reactor::Object {
4343

4444
struct IdleEvt
4545
{
46-
~IdleEvt() { cancel(); }
46+
~IdleEvt();
4747

4848
void start();
4949
void cancel();
@@ -55,12 +55,15 @@ struct IdleEvt
5555
struct Handle
5656
:public uv_idle_t
5757
{
58-
static void CallbackRaw(uv_idle_t*);
58+
IdleEvt* m_pThis;
5959

60-
IMPLEMENT_GET_PARENT_OBJ(IdleEvt, m_Handle)
61-
} m_Handle;
60+
void CancelSafe();
6261

63-
bool m_Set = false;
62+
static void OnClosed(uv_handle_t*);
63+
static void OnSchedule(uv_idle_t*);
64+
};
65+
66+
Handle* m_pHandle = nullptr;
6467
};
6568

6669
}} //namespaces

wallet/api/api.cpp

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "wallet/transactions/swaps/swap_tx_description.h"
2525
#endif // BEAM_ATOMIC_SWAP_SUPPORT
2626
#include <regex>
27+
#include <string_view>
2728

2829
namespace beam::wallet {
2930
namespace {
@@ -145,6 +146,10 @@ void GetStatusResponseJson(const TxDescription& tx,
145146
};
146147
statusInterpreter = std::make_unique<AssetTxStatusInterpreter>(tx);
147148
}
149+
else if (tx.m_txType == TxType::PushTransaction)
150+
{
151+
statusInterpreter = std::make_unique<MaxPrivacyTxStatusInterpreter>(tx);
152+
}
148153
else if (tx.m_txType == TxType::AtomicSwap)
149154
{
150155
#ifdef BEAM_ATOMIC_SWAP_SUPPORT
@@ -156,8 +161,8 @@ void GetStatusResponseJson(const TxDescription& tx,
156161
{"txId", TxIDToString(tx.m_txId)},
157162
{"status", tx.m_status},
158163
{"status_string", statusInterpreter ? statusInterpreter->getStatus() : "unknown"},
159-
{"sender", std::to_string(tx.m_sender ? tx.m_myId : tx.m_peerId)},
160-
{"receiver", std::to_string(tx.m_sender ? tx.m_peerId : tx.m_myId)},
164+
{"sender", tx.getAddressFrom()},
165+
{"receiver", tx.getAddressTo()},
161166
{"value", tx.m_amount},
162167
{"comment", std::string{ tx.m_message.begin(), tx.m_message.end() }},
163168
{"create_time", tx.m_createTime},
@@ -849,7 +854,37 @@ OfferInput collectOfferInput(const JsonRpcId& id, const json& params)
849854
void WalletApi::onCreateAddressMessage(const JsonRpcId& id, const json& params)
850855
{
851856
CreateAddress createAddress;
857+
852858
FillAddressData(id, params, createAddress);
859+
860+
auto it = params.find("type");
861+
if (it != params.end())
862+
{
863+
static constexpr std::array<std::pair<std::string_view, TxAddressType>, 4> types =
864+
{
865+
{
866+
{"regular", TxAddressType::Regular},
867+
{"offline", TxAddressType::Offline},
868+
{"max_privacy", TxAddressType::MaxPrivacy},
869+
{"public_offline", TxAddressType::PublicOffline}
870+
}
871+
};
872+
auto t = std::find_if(types.begin(), types.end(), [&](const auto& p) { return p.first == it->get<std::string>(); });
873+
if (t != types.end())
874+
{
875+
createAddress.type = t->second;
876+
}
877+
}
878+
it = params.find("new_style_regular");
879+
if (it != params.end())
880+
{
881+
createAddress.newStyleRegular = it->get<bool>();
882+
}
883+
it = params.find("offline_payments");
884+
if (it != params.end())
885+
{
886+
createAddress.offlinePayments = it->get<uint32_t>();
887+
}
853888
getHandler().onMessage(id, createAddress);
854889
}
855890

@@ -930,21 +965,18 @@ OfferInput collectOfferInput(const JsonRpcId& id, const json& params)
930965
auto txParams = ParseParameters(addressOrToken);
931966
if (!txParams)
932967
{
933-
throw jsonrpc_exception{ ApiError::InvalidAddress , "Invalid receiver address or token.", id };
968+
throw jsonrpc_exception{ ApiError::InvalidAddress , "Invalid receiver address.", id };
934969
}
935-
send.txParameters = *txParams;
936-
937-
if (auto peerID = send.txParameters.GetParameter<WalletID>(TxParameterID::PeerID); peerID)
970+
send.txParameters = std::move(*txParams);
971+
auto peerID = send.txParameters.GetParameter<WalletID>(beam::wallet::TxParameterID::PeerID);
972+
if (peerID)
938973
{
939974
send.address = *peerID;
940-
if (std::to_string(*peerID) != addressOrToken)
941-
{
942-
send.txParameters.SetParameter(beam::wallet::TxParameterID::OriginalToken, addressOrToken);
943-
}
944975
}
945-
else
976+
977+
if (!peerID || std::to_string(*peerID) != addressOrToken)
946978
{
947-
throw jsonrpc_exception{ ApiError::InvalidAddress , "Invalid receiver address.", id };
979+
send.txParameters.SetParameter(beam::wallet::TxParameterID::OriginalToken, addressOrToken);
948980
}
949981

950982
if (existsJsonParam(params, "from"))
@@ -1487,7 +1519,7 @@ OfferInput collectOfferInput(const JsonRpcId& id, const json& params)
14871519
{
14881520
{JsonRpcHrd, JsonRpcVerHrd},
14891521
{"id", id},
1490-
{"result", std::to_string(res.address)}
1522+
{"result", res.address}
14911523
};
14921524
}
14931525

@@ -1760,7 +1792,8 @@ OfferInput collectOfferInput(const JsonRpcId& id, const json& params)
17601792
resItem.tx,
17611793
item,
17621794
resItem.txHeight,
1763-
resItem.systemHeight);
1795+
resItem.systemHeight,
1796+
true);
17641797
msg["result"].push_back(item);
17651798
}
17661799
}

wallet/api/api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,12 @@ namespace beam::wallet
262262

263263
struct CreateAddress : AddressData
264264
{
265+
TxAddressType type = TxAddressType::Regular;
266+
bool newStyleRegular = false; // by default we generate SBBS addresses for regular type
267+
uint32_t offlinePayments = 10;
265268
struct Response
266269
{
267-
WalletID address;
270+
std::string address;
268271
};
269272
};
270273

wallet/api/api.rest

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,18 @@ content-type: application/json-rpc
239239
"params": {}
240240
}
241241

242+
243+
######## Explorer node #######################
244+
###
245+
246+
GET http://127.0.0.1:8888/status HTTP/1.1
247+
248+
###
249+
250+
GET http://127.0.0.1:8888/blocks?height=13600&n=100 HTTP/1.1
251+
252+
###
253+
254+
GET http://127.0.0.1:8888/swap_offers HTTP/1.1
255+
242256
###

wallet/api/api_cli.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#include "wallet/client/extensions/offers_board/swap_offers_board.h"
6262
#endif // BEAM_ATOMIC_SWAP_SUPPORT
6363

64+
#include "wallet/transactions/lelantus/lelantus_reg_creators.h"
65+
6466
#include "nlohmann/json.hpp"
6567
#include "version.h"
6668

@@ -706,7 +708,7 @@ int main(int argc, char* argv[])
706708
std::string whitelist;
707709

708710
uint32_t logCleanupPeriod;
709-
711+
bool enableLelentus = false;
710712
} options;
711713

712714
TlsOptions tlsOptions;
@@ -729,7 +731,8 @@ int main(int argc, char* argv[])
729731
(cli::IP_WHITELIST, po::value<std::string>(&options.whitelist)->default_value(""), "IP whitelist")
730732
(cli::LOG_CLEANUP_DAYS, po::value<uint32_t>(&options.logCleanupPeriod)->default_value(5), "old logfiles cleanup period(days)")
731733
(cli::NODE_POLL_PERIOD, po::value<Nonnegative<uint32_t>>(&options.pollPeriod_ms)->default_value(Nonnegative<uint32_t>(0)), "Node poll period in milliseconds. Set to 0 to keep connection. Anyway poll period would be no less than the expected rate of blocks if it is less then it will be rounded up to block rate value.")
732-
(cli::WITH_ASSETS, po::bool_switch()->default_value(false), "enable confidential assets transactions");
734+
(cli::WITH_ASSETS, po::bool_switch()->default_value(false), "enable confidential assets transactions")
735+
(cli::ENABLE_LELANTUS, po::bool_switch()->default_value(false), "enable Lelantus MW transactions");
733736
;
734737

735738
po::options_description authDesc("User authorization options");
@@ -850,6 +853,8 @@ int main(int argc, char* argv[])
850853
// this should be exactly CLI flag value to print correct error messages
851854
// Rules::CA.Enabled would be checked as well but later
852855
wallet::g_AssetsEnabled = vm[cli::WITH_ASSETS].as<bool>();
856+
857+
options.enableLelentus = vm[cli::ENABLE_LELANTUS].as<bool>();
853858
}
854859

855860
io::Address listenTo = io::Address().port(options.port);
@@ -896,6 +901,11 @@ int main(int argc, char* argv[])
896901
RegisterAssetCreators(*wallet);
897902
}
898903

904+
if (options.enableLelentus)
905+
{
906+
lelantus::RegisterCreators(*wallet, walletDB);
907+
}
908+
899909
// All TxCreators must be registered by this point
900910
wallet->ResumeAllTransactions();
901911

0 commit comments

Comments
 (0)