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

Recover build/main #16

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build
dist
*.pyc
.idea
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "wallet-core"]
path = wallet-core
url = https://github.com/trustwallet/wallet-core.git
branch = master
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import os
from glob import glob
from distutils.core import setup, Extension
from setuptools import setup, Extension

# Use clang since wallet-core headers don't compile with gcc
if 'CC' not in os.environ:
Expand All @@ -28,6 +28,7 @@
WALLET_CORE_INCLUDE = os.path.join(WALLET_CORE_ROOT, 'include')
WALLET_CORE_BUILD = os.path.join(WALLET_CORE_ROOT, 'build')
TREZOR_CRYPTO = os.path.join(WALLET_CORE_BUILD, 'trezor-crypto')
RUST_LIB_PATH = os.path.join(WALLET_CORE_ROOT, 'rust', 'target', 'release')

link_args = []
# Add --coverage link arg otherwise linking fails with undefined symbols
Expand All @@ -41,8 +42,8 @@

module = Extension('walletcore',
include_dirs=[WALLET_CORE_INCLUDE, 'src'],
library_dirs=[WALLET_CORE_BUILD, TREZOR_CRYPTO],
libraries=['TrustWalletCore', 'protobuf', 'TrezorCrypto'],
library_dirs=[WALLET_CORE_BUILD, TREZOR_CRYPTO, RUST_LIB_PATH],
libraries=['TrustWalletCore', 'protobuf', 'TrezorCrypto', 'wallet_core_rs'],
extra_compile_args=compile_args,
extra_link_args=link_args,
sources=glob('src/*.cc') + glob('src/generated/*.cc'))
Expand Down
18 changes: 9 additions & 9 deletions src/generated/Account.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ static PyObject* PyAccountAddress(PyAccountObject* self, void*) {
return PyUnicode_FromTWString(prop);
}

// getter function for Coin
static const char PyAccountCoin_doc[] =
"enum TWCoinType TWAccountCoin(struct TWAccount* account)";
static PyObject* PyAccountCoin(PyAccountObject* self, void*) {
TWCoinType prop = TWAccountCoin(self->value);
return PyCoinType_FromTWCoinType(prop);
}

// getter function for Derivation
static const char PyAccountDerivation_doc[] =
"enum TWDerivation TWAccountDerivation(struct TWAccount* account)";
Expand Down Expand Up @@ -123,14 +131,6 @@ static PyObject* PyAccountExtendedPublicKey(PyAccountObject* self, void*) {
return PyUnicode_FromTWString(prop);
}

// getter function for Coin
static const char PyAccountCoin_doc[] =
"enum TWCoinType TWAccountCoin(struct TWAccount* account)";
static PyObject* PyAccountCoin(PyAccountObject* self, void*) {
TWCoinType prop = TWAccountCoin(self->value);
return PyCoinType_FromTWCoinType(prop);
}

// static method function for Create
static const char PyAccountCreate_doc[] =
"struct TWAccount* TWAccountCreate(TWString* address, enum TWCoinType "
Expand Down Expand Up @@ -190,14 +190,14 @@ static PyObject* PyAccountCreate(PyAccountObject* self,

static const PyGetSetDef get_set_defs[] = {
{"address", (getter)PyAccountAddress, nullptr, PyAccountAddress_doc},
{"coin", (getter)PyAccountCoin, nullptr, PyAccountCoin_doc},
{"derivation", (getter)PyAccountDerivation, nullptr,
PyAccountDerivation_doc},
{"derivation_path", (getter)PyAccountDerivationPath, nullptr,
PyAccountDerivationPath_doc},
{"public_key", (getter)PyAccountPublicKey, nullptr, PyAccountPublicKey_doc},
{"extended_public_key", (getter)PyAccountExtendedPublicKey, nullptr,
PyAccountExtendedPublicKey_doc},
{"coin", (getter)PyAccountCoin, nullptr, PyAccountCoin_doc},
{}};

static const PyMethodDef method_defs[] = {
Expand Down
38 changes: 38 additions & 0 deletions src/generated/AnyAddress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "String.h"
#include "generated/CoinType.h"
#include "generated/Derivation.h"
#include "generated/FilecoinAddressType.h"
#include "generated/PublicKey.h"

struct PyAnyAddressObject {
Expand Down Expand Up @@ -472,6 +473,39 @@ static PyObject* PyAnyAddressCreateSS58WithPublicKey(PyAnyAddressObject* self,
return PyAnyAddress_FromTWAnyAddress(result);
}

// static method function for CreateWithPublicKeyFilecoinAddressType
static const char PyAnyAddressCreateWithPublicKeyFilecoinAddressType_doc[] =
"struct TWAnyAddress* "
"TWAnyAddressCreateWithPublicKeyFilecoinAddressType(struct TWPublicKey* "
"publicKey, enum TWFilecoinAddressType filecoinAddressType)";
static PyObject* PyAnyAddressCreateWithPublicKeyFilecoinAddressType(
PyAnyAddressObject* self,
PyObject* const* args,
Py_ssize_t nargs) {
if (nargs != 2) {
PyErr_Format(PyExc_TypeError, "Expect 2 args, but %d args are passed in.",
nargs);
return nullptr;
}

if (!PyPublicKey_Check(args[0])) {
PyErr_SetString(PyExc_TypeError, "The arg 0 is not in type PublicKey");
return nullptr;
}
auto arg0 = PyPublicKey_GetTWPublicKey(args[0]);

if (!PyFilecoinAddressType_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"The arg 1 is not in type FilecoinAddressType");
return nullptr;
}
auto arg1 = PyFilecoinAddressType_GetTWFilecoinAddressType(args[1]);

TWAnyAddress* result =
TWAnyAddressCreateWithPublicKeyFilecoinAddressType(arg0, arg1);
return PyAnyAddress_FromTWAnyAddress(result);
}

// properties

static const PyGetSetDef get_set_defs[] = {
Expand Down Expand Up @@ -508,6 +542,10 @@ static const PyMethodDef method_defs[] = {
{"create_ss58_with_public_key",
(PyCFunction)PyAnyAddressCreateSS58WithPublicKey,
METH_FASTCALL | METH_STATIC, PyAnyAddressCreateSS58WithPublicKey_doc},
{"create_with_public_key_filecoin_address_type",
(PyCFunction)PyAnyAddressCreateWithPublicKeyFilecoinAddressType,
METH_FASTCALL | METH_STATIC,
PyAnyAddressCreateWithPublicKeyFilecoinAddressType_doc},
{}};

bool PyInit_AnyAddress(PyObject* module) {
Expand Down
4 changes: 3 additions & 1 deletion src/generated/Blockchain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static Constant constants[] = {
{ TWBlockchainCardano, "Cardano", nullptr },
{ TWBlockchainNEO, "NEO", nullptr },
{ TWBlockchainFilecoin, "Filecoin", nullptr },
{ TWBlockchainElrondNetwork, "ElrondNetwork", nullptr },
{ TWBlockchainMultiversX, "MultiversX", nullptr },
{ TWBlockchainOasisNetwork, "OasisNetwork", nullptr },
{ TWBlockchainDecred, "Decred", nullptr },
{ TWBlockchainZcash, "Zcash", nullptr },
Expand All @@ -102,6 +102,8 @@ static Constant constants[] = {
{ TWBlockchainEverscale, "Everscale", nullptr },
{ TWBlockchainAptos, "Aptos", nullptr },
{ TWBlockchainHedera, "Hedera", nullptr },
{ TWBlockchainTheOpenNetwork, "TheOpenNetwork", nullptr },
{ TWBlockchainSui, "Sui", nullptr },
// clang-format on
};

Expand Down
11 changes: 9 additions & 2 deletions src/generated/CoinType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static Constant constants[] = {
{ TWCoinTypeDigiByte, "DigiByte", nullptr },
{ TWCoinTypeDogecoin, "Dogecoin", nullptr },
{ TWCoinTypeEOS, "EOS", nullptr },
{ TWCoinTypeWAX, "WAX", nullptr },
{ TWCoinTypeEthereum, "Ethereum", nullptr },
{ TWCoinTypeEthereumClassic, "EthereumClassic", nullptr },
{ TWCoinTypeFIO, "FIO", nullptr },
Expand All @@ -108,7 +109,7 @@ static Constant constants[] = {
{ TWCoinTypeStellar, "Stellar", nullptr },
{ TWCoinTypeTezos, "Tezos", nullptr },
{ TWCoinTypeTheta, "Theta", nullptr },
{ TWCoinTypeThunderToken, "ThunderToken", nullptr },
{ TWCoinTypeThunderCore, "ThunderCore", nullptr },
{ TWCoinTypeNEO, "NEO", nullptr },
{ TWCoinTypeTomoChain, "TomoChain", nullptr },
{ TWCoinTypeTron, "Tron", nullptr },
Expand All @@ -128,7 +129,7 @@ static Constant constants[] = {
{ TWCoinTypeKusama, "Kusama", nullptr },
{ TWCoinTypePolkadot, "Polkadot", nullptr },
{ TWCoinTypeFilecoin, "Filecoin", nullptr },
{ TWCoinTypeElrond, "Elrond", nullptr },
{ TWCoinTypeMultiversX, "MultiversX", nullptr },
{ TWCoinTypeBandChain, "BandChain", nullptr },
{ TWCoinTypeSmartChainLegacy, "SmartChainLegacy", nullptr },
{ TWCoinTypeSmartChain, "SmartChain", nullptr },
Expand Down Expand Up @@ -167,6 +168,12 @@ static Constant constants[] = {
{ TWCoinTypeAptos, "Aptos", nullptr },
{ TWCoinTypeHedera, "Hedera", nullptr },
{ TWCoinTypeSecret, "Secret", nullptr },
{ TWCoinTypeNativeInjective, "NativeInjective", nullptr },
{ TWCoinTypeAgoric, "Agoric", nullptr },
{ TWCoinTypeTON, "TON", nullptr },
{ TWCoinTypeSui, "Sui", nullptr },
{ TWCoinTypeStargaze, "Stargaze", nullptr },
{ TWCoinTypePolygonzkEVM, "PolygonzkEVM", nullptr },
// clang-format on
};

Expand Down
1 change: 1 addition & 0 deletions src/generated/Derivation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static Constant constants[] = {
{ TWDerivationCustom, "Custom", nullptr },
{ TWDerivationBitcoinSegwit, "BitcoinSegwit", nullptr },
{ TWDerivationBitcoinLegacy, "BitcoinLegacy", nullptr },
{ TWDerivationBitcoinTestnet, "BitcoinTestnet", nullptr },
{ TWDerivationLitecoinLegacy, "LitecoinLegacy", nullptr },
{ TWDerivationSolanaSolana, "SolanaSolana", nullptr },
// clang-format on
Expand Down
157 changes: 157 additions & 0 deletions src/generated/Ethereum.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// Copyright 2021 Peng Huang <[email protected]>
// This file is part of Wallet-core-python.
//
// Wallet-core-python is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Wallet-core-python is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Wallet-core-python. If not, see <https://www.gnu.org/licenses/>.
//
// NOTE: this is a GENERATED FILE, changes made here WILL BE LOST.

#include "generated/Ethereum.h"

#include "String.h"

struct PyEthereumObject {
PyObject_HEAD;
};

static PyTypeObject PyEthereumType = {
// clang-format off
PyVarObject_HEAD_INIT(NULL, 0)
// clang-format on
"walletcore.Ethereum", /* tp_name */
sizeof(PyEthereumObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
nullptr, /* tp_doc */
};

// static method function for Eip2645GetPath
static const char PyEthereumEip2645GetPath_doc[] =
"TWString* TWEthereumEip2645GetPath(TWString* ethAddress, TWString* layer, "
"TWString* application, TWString* index)";
static PyObject* PyEthereumEip2645GetPath(PyEthereumObject* self,
PyObject* const* args,
Py_ssize_t nargs) {
if (nargs != 4) {
PyErr_Format(PyExc_TypeError, "Expect 4 args, but %d args are passed in.",
nargs);
return nullptr;
}

if (!PyUnicode_Check(args[0])) {
PyErr_SetString(PyExc_TypeError, "The arg 0 is not in type Unicode");
return nullptr;
}
auto arg0 = PyUnicode_GetTWString(args[0]);

if (!PyUnicode_Check(args[1])) {
PyErr_SetString(PyExc_TypeError, "The arg 1 is not in type Unicode");
return nullptr;
}
auto arg1 = PyUnicode_GetTWString(args[1]);

if (!PyUnicode_Check(args[2])) {
PyErr_SetString(PyExc_TypeError, "The arg 2 is not in type Unicode");
return nullptr;
}
auto arg2 = PyUnicode_GetTWString(args[2]);

if (!PyUnicode_Check(args[3])) {
PyErr_SetString(PyExc_TypeError, "The arg 3 is not in type Unicode");
return nullptr;
}
auto arg3 = PyUnicode_GetTWString(args[3]);

TWStringPtr result(
TWEthereumEip2645GetPath(arg0.get(), arg1.get(), arg2.get(), arg3.get()));
return PyUnicode_FromTWString(result);
}

// static method function for Eip4337GetDeploymentAddress
static const char PyEthereumEip4337GetDeploymentAddress_doc[] =
"TWString* TWEthereumEip4337GetDeploymentAddress(TWString* factoryAddress, "
"TWString* logicAddress, TWString* ownerAddress)";
static PyObject* PyEthereumEip4337GetDeploymentAddress(PyEthereumObject* self,
PyObject* const* args,
Py_ssize_t nargs) {
if (nargs != 3) {
PyErr_Format(PyExc_TypeError, "Expect 3 args, but %d args are passed in.",
nargs);
return nullptr;
}

if (!PyUnicode_Check(args[0])) {
PyErr_SetString(PyExc_TypeError, "The arg 0 is not in type Unicode");
return nullptr;
}
auto arg0 = PyUnicode_GetTWString(args[0]);

if (!PyUnicode_Check(args[1])) {
PyErr_SetString(PyExc_TypeError, "The arg 1 is not in type Unicode");
return nullptr;
}
auto arg1 = PyUnicode_GetTWString(args[1]);

if (!PyUnicode_Check(args[2])) {
PyErr_SetString(PyExc_TypeError, "The arg 2 is not in type Unicode");
return nullptr;
}
auto arg2 = PyUnicode_GetTWString(args[2]);

TWStringPtr result(TWEthereumEip4337GetDeploymentAddress(
arg0.get(), arg1.get(), arg2.get()));
return PyUnicode_FromTWString(result);
}

// properties

static const PyGetSetDef get_set_defs[] = {{}};

static const PyMethodDef method_defs[] = {
{"eip2645_get_path", (PyCFunction)PyEthereumEip2645GetPath,
METH_FASTCALL | METH_STATIC, PyEthereumEip2645GetPath_doc},
{"eip4337_get_deployment_address",
(PyCFunction)PyEthereumEip4337GetDeploymentAddress,
METH_FASTCALL | METH_STATIC, PyEthereumEip4337GetDeploymentAddress_doc},
{}};

bool PyInit_Ethereum(PyObject* module) {
PyEthereumType.tp_getset = (PyGetSetDef*)get_set_defs;
PyEthereumType.tp_methods = (PyMethodDef*)method_defs;

if (PyType_Ready(&PyEthereumType) < 0)
return false;

Py_INCREF(&PyEthereumType);
if (PyModule_AddObject(module, "Ethereum", (PyObject*)&PyEthereumType) < 0) {
Py_DECREF(&PyEthereumType);
return false;
}

return true;
}
27 changes: 27 additions & 0 deletions src/generated/Ethereum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2021 Peng Huang <[email protected]>
// This file is part of Wallet-core-python.
//
// Wallet-core-python is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Wallet-core-python is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Wallet-core-python. If not, see <https://www.gnu.org/licenses/>.
//
// NOTE: this is a GENERATED FILE, changes made here WILL BE LOST.

#pragma once

#define PY_SSIZE_T_CLEAN
#include <Python.h>

#include <TrustWalletCore/TWEthereum.h>

// Initialize for PyEthereum. It is called by python module init function.
bool PyInit_Ethereum(PyObject* module);
Loading