Skip to content

Commit

Permalink
Problem: not exposing c++ api for wc 2.0 sign , send tx cronos-labs#453
Browse files Browse the repository at this point in the history
working

print qr

port wc 1.0 apis

reformat

tidy up

testing send tx

add makefile

add qrcode

move use

send_tx code added

add signing

reformat

fix signing

reformat

add zero padding to hex

tidy up

tidy up

refactoring

not use chain-id

remove Makefile

restore main
  • Loading branch information
leejw51crypto committed Jun 6, 2023
1 parent 0f5e0bc commit 41ba119
Show file tree
Hide file tree
Showing 10 changed files with 850 additions and 26 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,21 @@ demo/cronos.h
demo/sdk

install

wallet-connect/qrcode.png

wallet-connect/session.bin

defi-wallet-core-rs

demo/third_party/easywsclient

demo/third_party/json

wallet-connect/yarn.lock

wallet-connect/node_modules/

.DS_Store

sessioninfo2.json
153 changes: 151 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions demo/extra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "sdk/include/rust/cxx.h"
#include "third_party/easywsclient/easywsclient.hpp"
#include "third_party/json/single_include/nlohmann/json.hpp"
#include <cassert>
#include <atomic>
#include <cassert>
#include <chrono>
Expand Down Expand Up @@ -363,16 +364,17 @@ void test_wallet_connect() {
* @summary test wallet connect 2.0
* @description basic test for wallet connect 2.0
*/

void test_wallet_connect2() {
std::string mycronosrpc = getEnv("CRONOSRPC").c_str();
bool test_personal = true;
bool test_basic = false;
bool test_personal = false;
bool test_basic = true;
bool test_nft = false;
std::string filename = "sessioninfo2.json";
bool exit_program = false;
try {
Box<Walletconnect2Client> client = make_new_client2(filename);
String uri = client->print_uri();
std::cout << "uri= " << uri.c_str() << std::endl;
WalletConnect2EnsureSessionResult result =
client->ensure_session_blocking(60000);
std::cout << "session result=" << result.eip155.accounts.size()
Expand Down Expand Up @@ -405,14 +407,37 @@ void test_wallet_connect2() {
}

assert(result.eip155.accounts.size() > 0);
bool test_personal = true;

if (test_personal) {
Vec<uint8_t> sig1 = client->sign_personal_blocking(
"hello", result.eip155.accounts.at(0).address.address);
std::cout << "signature length=" << sig1.size() << endl;
}

if (test_basic) {
std::string fromaddress = getenv("MYFROMADDRESS");
std::cout << "mycronosrpc=" << mycronosrpc << endl;
std::cout << "fromaddress=" << fromaddress << endl;
std::string toaddress = getenv("MYTOADDRESS");
std::cout << "toaddress=" << toaddress << endl;
std::string mynonce = org::defi_wallet_core::get_eth_nonce(
fromaddress.c_str(), mycronosrpc)
.c_str();
std::cout << "nonce=" << mynonce << endl;
WalletConnectTxEip155 info;
info.to = toaddress;
info.common.gas_limit = "21000"; // gas limit
info.common.gas_price = "10000"; // gas price
info.value = "100000000000000"; // 0.0001 eth
info.data = Vec<uint8_t>();
info.common.nonce = mynonce;
info.common.chainid = 1;

assert(result.eip155.accounts.size() > 0);
Vec<uint8_t> rawtx = client->sign_eip155_transaction_blocking(
info, result.eip155.accounts[0].address.address);
}

std::cout << "enter q to exit" << std::endl;
while (true) {
// read input, if q is pressed, quit
Expand Down
1 change: 1 addition & 0 deletions demo/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int main(int argc, char *argv[]) {
test_interval();
test_blackscout_cronoscan();
test_wallet_connect();
I

} catch (const std::exception &e) {
// Use `Assertion failed`, the same as `assert` function
Expand Down
Loading

0 comments on commit 41ba119

Please sign in to comment.