Skip to content

Commit

Permalink
update v2.0.0-p3
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhi committed Oct 15, 2024
1 parent 3e6bdc9 commit 8214717
Show file tree
Hide file tree
Showing 46 changed files with 568,478 additions and 2,041 deletions.
7 changes: 6 additions & 1 deletion Dockerfile.source
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ RUN go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
# Build and install qclient
WORKDIR /opt/ceremonyclient/client

RUN go mod tidy && go build -o qclient ./main.go
RUN chmod +x ./build.sh && ./build.sh -o qclient && cp qclient /go/bin

# Allows exporting single binary
FROM scratch as qclient
COPY --from=build /go/bin/qclient /qclient
ENTRYPOINT [ "/qclient" ]

# Allows exporting single binary
FROM scratch AS node
Expand Down
17 changes: 17 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,33 @@ tasks:
- bls48581/generate.sh
- node/build.sh -o build/arm64_macos/node

build_qclient_arm64_macos:
desc: Build the QClient node binary for MacOS ARM. Outputs to client/build
cmds:
- vdf/generate.sh
- bls48581/generate.sh
- client/build.sh -o build/arm64_macos/qclient

build_node_arm64_linux:
desc: Build the Quilibrium node binary for ARM64 Linux. Outputs to node/build.
cmds:
- docker build --platform linux/arm64 -f Dockerfile.source --output node/build/arm64_linux --target=node .

build_qclient_arm64_linux:
desc: Build the QClient node binary for ARM64 Linux. Outputs to client/build.
cmds:
- docker build --platform linux/arm64 -f Dockerfile.source --output client/build/arm64_linux --target=qclient .

build_node_amd64_linux:
desc: Build the Quilibrium node binary for AMD64 Linux. Outputs to node/build.
cmds:
- docker build --platform linux/amd64 -f Dockerfile.source --output node/build/amd64_linux --target=node .

build_qclient_amd64_linux:
desc: Build the QClient node binary for AMD64 Linux. Outputs to node/build.
cmds:
- docker build --platform linux/amd64 -f Dockerfile.source --output client/build/amd64_linux --target=qclient .

build:source:
desc: Build the Quilibrium docker image from source.
cmds:
Expand Down
35 changes: 35 additions & 0 deletions client/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -euxo pipefail

# This script builds the node binary for the current platform and statically links it with VDF static lib.
# Assumes that the VDF library has been built by running the generate.sh script in the `../vdf` directory.

ROOT_DIR="${ROOT_DIR:-$( cd "$(dirname "$(realpath "$( dirname "${BASH_SOURCE[0]}" )")")" >/dev/null 2>&1 && pwd )}"

CLIENT_DIR="$ROOT_DIR/client"
BINARIES_DIR="$ROOT_DIR/target/release"

pushd "$CLIENT_DIR" > /dev/null

export CGO_ENABLED=1

os_type="$(uname)"
case "$os_type" in
"Darwin")
# Check if the architecture is ARM
if [[ "$(uname -m)" == "arm64" ]]; then
# MacOS ld doesn't support -Bstatic and -Bdynamic, so it's important that there is only a static version of the library
go build -ldflags "-linkmode 'external' -extldflags '-L$BINARIES_DIR -lvdf -lbls48581 -ldl -lm'" "$@"
else
echo "Unsupported platform"
exit 1
fi
;;
"Linux")
go build -ldflags "-linkmode 'external' -extldflags '-L$BINARIES_DIR -Wl,-Bstatic -lvdf -lbls48581 -Wl,-Bdynamic -ldl -lm'" "$@"
;;
*)
echo "Unsupported platform"
exit 1
;;
esac
15 changes: 1 addition & 14 deletions client/cmd/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

import (
"fmt"
"math/big"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -18,18 +16,7 @@ var acceptCmd = &cobra.Command{
PendingTransaction - the address of the pending transfer
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("invalid command")
os.Exit(1)
}

_, ok := new(big.Int).SetString(args[0], 0)
if !ok {
fmt.Println("invalid PendingTransaction")
os.Exit(1)
}

fmt.Println("25 QUIL (Coin 0x2688997f2776ab5993894ed04fcdac05577cf2494ddfedf356ebf8bd3de464ab)")
fmt.Println("command not yet available")
},
}

Expand Down
2 changes: 1 addition & 1 deletion client/cmd/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var allCmd = &cobra.Command{
Use: "all",
Short: "Mints all available token rewards",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("1520.381923 QUIL (Coin 0x162ad88c319060b4f5ea6dbf9a0c2cd82d3d70dfc22d5fc99ca5371083d68416)")
fmt.Println("command not yet available")
},
}

Expand Down
36 changes: 35 additions & 1 deletion client/cmd/balance.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
package cmd

import (
"context"
"fmt"
"math/big"

"github.com/iden3/go-iden3-crypto/poseidon"
"github.com/spf13/cobra"
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
)

var balanceCmd = &cobra.Command{
Use: "balance",
Short: "Lists the total balance of tokens in the managing account",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("1545.381923 QUIL (Account 0x026a5cf3d486b8e8733060d6ce0060074616f0f925671a0886faef744412dc8a)")
conn, err := GetGRPCClient()
if err != nil {
panic(err)
}
defer conn.Close()

client := protobufs.NewNodeServiceClient(conn)
peerId := GetPeerIDFromConfig(NodeConfig)
addr, err := poseidon.HashBytes([]byte(peerId))
if err != nil {
panic(err)
}

addrBytes := addr.FillBytes(make([]byte, 32))
info, err := client.GetTokenInfo(
context.Background(),
&protobufs.GetTokenInfoRequest{
Address: addrBytes,
},
)
if err != nil {
panic(err)
}

if info.OwnedTokens == nil {
panic("invalid response from RPC")
}
tokens := new(big.Int).SetBytes(info.OwnedTokens)
conversionFactor, _ := new(big.Int).SetString("1DCD65000", 16)
r := new(big.Rat).SetFrac(tokens, conversionFactor)
fmt.Println("Total balance:", r.FloatString(12), "QUIL")
},
}

Expand Down
Loading

0 comments on commit 8214717

Please sign in to comment.