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
  • Loading branch information
leejw51crypto committed Jun 5, 2023
1 parent 0f5e0bc commit f45f4ec
Show file tree
Hide file tree
Showing 10 changed files with 872 additions and 24 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.

39 changes: 35 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,43 @@ 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);

/*auto receipt = org::defi_wallet_core::broadcast_eth_signed_raw_tx(
rawtx, mycronosrpc, 3000);
std::cout << "transaction_hash="
<< bytes_to_hex_string(receipt.transaction_hash).c_str()
<< endl;*/
}

std::cout << "enter q to exit" << std::endl;
while (true) {
// read input, if q is pressed, quit
Expand Down
Loading

0 comments on commit f45f4ec

Please sign in to comment.