Last active
December 5, 2019 06:23
-
-
Save hewigovens/ad1169e4b51fb8cc2f76aa0937c28d66 to your computer and use it in GitHub Desktop.
call wallet core from go on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo CFLAGS: -I${SRCDIR}/wallet-core/include | |
// #cgo LDFLAGS: -L${SRCDIR}/wallet-core/build/ios -lTrezorCrypto -lTrustWalletCore -lprotobuf -lc++ | |
// #include <TrustWalletCore/TWHDWallet.h> | |
// #include <TrustWalletCore/TWString.h> | |
import "C" | |
import "fmt" | |
func main() { | |
fmt.Println("==> calling wallet core from go") | |
str := C.TWStringCreateWithUTF8Bytes(C.CString("confirm bleak useless tail chalk destroy horn step bulb genuine attract split")) | |
defer C.TWStringDelete(str) | |
valid := C.TWHDWalletIsValid(str) | |
fmt.Println("<== mnemonic is valid: ", valid) | |
} |
build project depends on wallet-core for linux
The best way I think is rely on the wallet-core docker image as a base image. Otherwise, need manually install all wallet-core's tool's linux version (clang, ruby, protobuf) and need to cope with different linux distribution (ubuntu, aws linux)
Let's say we have go project A depends on wallet-core and an upper go project B depends on A. Our binary is built from project B.
A's makefile should look like this:
get_walletcore:
if [ ! -d "./wallet-core" ]; then \
git clone https://github.com/ackratos/wallet-core.git && cd wallet-core && git checkout tss; \
fi
build_docker: get_walletcore
cd wallet-core && docker build -t tss/wallet-core .
docker build -t tss/tss-core .
build_inside: get_walletcore
cd wallet-core && \
set -e && \
tools/install-dependencies && \
tools/generate-files && \
cmake -H. -Bbuild && \
make -Cbuild
A's dockerfile looks like:
FROM tss/wallet-core
# Install the basics
RUN apt-get update && apt-get install -y wget && wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.13.4.linux-amd64.tar.gz
COPY . /tss-core
RUN . ~/.bashrc \
&& cd /tss-core \
&& make build_inside \
&& export PATH=$PATH:/usr/local/go/bin \
&& make build_go
CMD ["/bin/bash"]
B's go module build won't success without wallet-core lib is installed correctly, so within docker, we simply add a replace directive on go.mod to redirect it to the one in tss-core docker image.
B's makefile should look like:
build_docker:
docker images -q tss/tss-core
if [ $? -ne 0 ]; then \
git clone https://github.com/binance-chain/tss-core.git && cd tss-core && make build_docker; \
fi
docker build -t tss/tss-custody-server .
B's dockerfile should look like:
FROM tss/tss-core
COPY . /tss-custody-server
WORKDIR /tss-custody-server
RUN sed -i 's/replace github.com\/binance-chain\/tss-core => .*$/replace github.com\/binance-chain\/tss-core => \/tss-core/g' go.mod \
&& export PATH=$PATH:/usr/local/go/bin \
&& go build
EXPOSE 8080
CMD ["/tss-custody-server/tss-custody-server"]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git clone
https://github.com/hewigovens/wallet-core-carthage
and putmain.go
inrun
go build -o go-walletcore