Skip to content

Commit

Permalink
Merge pull request #313 from stratosnet/release
Browse files Browse the repository at this point in the history
Release v0.11.0 mainnet
  • Loading branch information
jinzuo-qsn authored Sep 18, 2023
2 parents 5aecd57 + 3167187 commit dab11c7
Show file tree
Hide file tree
Showing 30 changed files with 1,321 additions and 330 deletions.
35 changes: 28 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/make -f

BUILDDIR ?= $(CURDIR)/build
LEDGER_ENABLED ?= false

APP_VER := v0.10.0
APP_VER := v0.11.0
COMMIT := $(GIT_COMMIT_HASH)
TEST_DOCKER_REPO=stratos-chain-e2e

Expand All @@ -13,8 +14,25 @@ else
endif

ldflags= -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION)
ldflags += -X github.com/cosmos/cosmos-sdk/version.Name=stchain
ifeq ($(LEDGER_ENABLED),true)
build_tags += ledger
endif

ifeq (cleveldb,$(findstring cleveldb,$(BUILD_OPTIONS)))
build_tags += gcc cleveldb
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif

whitespace :=
whitespace := $(whitespace) $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
ldflags += -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

BUILD_FLAGS += -ldflags '$(ldflags)'
BUILD_FLAGS += -tags "$(build_tags)"

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

BUILD_TARGETS := build install

Expand All @@ -23,19 +41,22 @@ build: BUILD_ARGS=-o $(BUILDDIR)/
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
# go $@ -mod=readonly $(BUILD_ARGS) $(VERSION) ./cmd/...
go $@ $(BUILD_ARGS) $(BUILD_FLAGS) ./cmd/...
# CGO_ENABLED=1 CGO_LDFLAGS="-lsnappy" go $@ -mod=readonly $(BUILD_ARGS) $(VERSION) -tags "cleveldb" ./cmd/...
# CGO_ENABLED=1 CGO_LDFLAGS="-lsnappy" go $@ -mod=readonly $(BUILD_ARGS) $(BUILD_FLAGS) ./cmd/...

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
GOOS=linux GOARCH=amd64 $(MAKE) build

build-mac: go.sum
LEDGER_ENABLED=false GOOS=darwin GOARCH=amd64 $(MAKE) build
GOOS=darwin GOARCH=amd64 $(MAKE) build

build-windows: go.sum
LEDGER_ENABLED=false GOOS=windows GOARCH=amd64 $(MAKE) build
GOOS=windows GOARCH=amd64 $(MAKE) build

build-cleveldb: go.sum
CGO_ENABLED=1 CGO_LDFLAGS="-lsnappy" BUILD_OPTIONS=cleveldb $(MAKE) build

clean:
rm -rf $(BUILDDIR)/
Expand Down Expand Up @@ -73,4 +94,4 @@ build-docker:
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:latest

.PHONY: build-linux build-mac build clean
.PHONY: build-linux build-mac build-cleveldb build clean
16 changes: 7 additions & 9 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"fmt"
"sort"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
Expand All @@ -19,7 +17,7 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/go-bip39"

"github.com/spf13/cobra"
stratoshd "github.com/stratosnet/stratos-chain/crypto/hd"
stratos "github.com/stratosnet/stratos-chain/types"
)
Expand Down Expand Up @@ -97,12 +95,13 @@ func runAddCmdPrepare(cmd *cobra.Command, args []string) error {

/*
input
- bip39 mnemonic
- bip39 passphrase
- bip44 path
- local encryption password
- bip39 mnemonic
- bip39 passphrase
- bip44 path
- local encryption password
output
- armor encrypted private key (saved to file)
- armor encrypted private key (saved to file)
*/
func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *bufio.Reader) error {
var err error
Expand Down Expand Up @@ -207,7 +206,6 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
// If we're using ledger, only thing we need is the path and the bech32 prefix.
if useLedger {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()

info, err := kb.SaveLedgerKey(name, algo, bech32PrefixAccAddr, coinType, account, index)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/stchaind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"go/doc/comment"
"os"

"github.com/cosmos/cosmos-sdk/crypto/ledger"
"github.com/cosmos/cosmos-sdk/server"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stratosnet/stratos-chain/crypto/ethsecp256k1"

"github.com/stratosnet/stratos-chain/app"
stratos "github.com/stratosnet/stratos-chain/types"
Expand All @@ -20,6 +22,7 @@ var (

func main() {
registerDenoms()
ledger.InitLedger(ethsecp256k1.MakePubKey, ledger.SignMode_SIGN_MODE_DIRECT)

rootCmd, _ := NewRootCmd()
if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions crypto/ethsecp256k1/ethsecp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -52,6 +53,10 @@ func GenerateKey() (*PrivKey, error) {
}, nil
}

func MakePubKey(key []byte) types.PubKey {
return &PubKey{Key: key}
}

// Bytes returns the byte representation of the ECDSA Private Key.
func (privKey PrivKey) Bytes() []byte {
bz := make([]byte, len(privKey.Key))
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ require (
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.4 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down Expand Up @@ -152,6 +151,7 @@ require (
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 // indirect
github.com/stratosnet/ledger-stratos-go v0.0.0-20230728192009-175657d24cb0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down Expand Up @@ -179,7 +179,7 @@ require (
replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/stratosnet/cosmos-sdk v0.45.12-0.20230124002546-fd8c3abd07d5
github.com/cosmos/cosmos-sdk => github.com/stratosnet/cosmos-sdk v0.45.12-0.20230728194757-346af98d48ea
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ github.com/cosmos/ibc-go/v3 v3.0.0 h1:XUNplHVS51Q2gMnTFsFsH9QJ7flsovMamnltKbEgPQ
github.com/cosmos/ibc-go/v3 v3.0.0/go.mod h1:Mb+1NXiPOLd+CPFlOC6BKeAUaxXlhuWenMmRiUiSmwY=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
Expand Down Expand Up @@ -820,8 +818,10 @@ github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57N
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/stratosnet/cosmos-sdk v0.45.12-0.20230124002546-fd8c3abd07d5 h1:WjTdRjQkoPKDtp2gaGu9s/Cv5QC4ahRI9VRuex+XvQE=
github.com/stratosnet/cosmos-sdk v0.45.12-0.20230124002546-fd8c3abd07d5/go.mod h1:p8Nf05bzxH7rGhbEuC0L+GEX4Fwvq3MgYFbdTlprZLc=
github.com/stratosnet/cosmos-sdk v0.45.12-0.20230728194757-346af98d48ea h1:ydNdNYLXLaCK96GqMRL2nR5sPXdznATfe5xJOqzg+6s=
github.com/stratosnet/cosmos-sdk v0.45.12-0.20230728194757-346af98d48ea/go.mod h1:S+xNysh6M/EWH/iikUBZ0b1OdMd9jU/tfoHe8R27YGc=
github.com/stratosnet/ledger-stratos-go v0.0.0-20230728192009-175657d24cb0 h1:Y8vzNO2ieC7ViVbge7v0eT/ft3nzwVCH78soFeqSJr4=
github.com/stratosnet/ledger-stratos-go v0.0.0-20230728192009-175657d24cb0/go.mod h1:9T0Ii/AMWWnJRtvKYKB4kDdraaOP76J+K5/IbRXQgyc=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down
15 changes: 15 additions & 0 deletions proto/stratos/pot/v1/pot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ message VolumeReportRecord {
(gogoproto.moretags) = "yaml:\"tx_hash\""
];
}

message TotalReward {
repeated cosmos.base.v1beta1.Coin mining_reward = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "mining_reward",
(gogoproto.moretags) = "yaml:\"mining_reward\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos.base.v1beta1.Coin traffic_reward = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "traffic_reward",
(gogoproto.moretags) = "yaml:\"traffic_reward\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
15 changes: 15 additions & 0 deletions proto/stratos/pot/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ service Query {
rpc CirculationSupply(QueryCirculationSupplyRequest) returns (QueryCirculationSupplyResponse) {
option (google.api.http).get = "/stratos/pot/v1/circulation-supply";
}

rpc TotalRewardByEpoch(QueryTotalRewardByEpochRequest) returns (QueryTotalRewardByEpochResponse) {
option (google.api.http).get = "/stratos/pot/v1/total-reward/{epoch}";
}
}

// QueryVolumeReportRequest is request type for the Query/VolumeReport RPC method
Expand Down Expand Up @@ -142,4 +146,15 @@ message QueryCirculationSupplyResponse{
];
}

message QueryTotalRewardByEpochRequest {
int64 epoch = 1;
}

message QueryTotalRewardByEpochResponse {
TotalReward total_reward = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "total_reward",
(gogoproto.moretags) = "yaml:\"total_reward\""
];
}

24 changes: 22 additions & 2 deletions rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -407,6 +408,25 @@ func TmTxToEthTx(
bNumber = new(big.Int).SetUint64(*blockNumber)
}

to := new(common.Address)
value := new(big.Int).SetInt64(0)

// cosmos.bank.v1beta1.MsgSend
sendTx, ok := msg.(*banktypes.MsgSend)
if ok {
bFrom, err := sdk.AccAddressFromBech32(sendTx.FromAddress)
if err != nil {
return nil, err
}
bTo, err := sdk.AccAddressFromBech32(sendTx.ToAddress)
if err != nil {
return nil, err
}
from = common.BytesToAddress(bFrom.Bytes())
*to = common.BytesToAddress(bTo.Bytes())
value = sendTx.Amount.AmountOf(stratos.Wei).BigInt()
}

return &Transaction{
BlockHash: blockHash,
BlockNumber: (*hexutil.Big)(bNumber),
Expand All @@ -417,9 +437,9 @@ func TmTxToEthTx(
Hash: common.BytesToHash(tmTx.Hash()),
Input: make(hexutil.Bytes, 0),
Nonce: hexutil.Uint64(nonce),
To: new(common.Address),
To: to,
TransactionIndex: (*hexutil.Uint64)(index),
Value: (*hexutil.Big)(new(big.Int).SetInt64(0)), // NOTE: How to get value in generic way?
Value: (*hexutil.Big)(value),
V: (*hexutil.Big)(v),
R: (*hexutil.Big)(r),
S: (*hexutil.Big)(s),
Expand Down
2 changes: 1 addition & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func GetAPINamespaces() []string {
// DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
func DefaultJSONRPCConfig() *JSONRPCConfig {
return &JSONRPCConfig{
Enable: true,
Enable: false,
API: GetDefaultAPINamespaces(),
Address: DefaultJSONRPCAddress,
WsAddress: DefaultJSONRPCWsAddress,
Expand Down
40 changes: 40 additions & 0 deletions x/pot/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryParams(),
GetCmdQueryTotalMinedTokens(),
GetCmdQueryCirculationSupply(),
GetCmdQueryTotalRewardByEpoch(),
)

return potQueryCmd
Expand Down Expand Up @@ -177,3 +178,42 @@ func checkFlagEpoch(epochStr string) (sdk.Int, error) {
epoch := sdk.NewInt(epochInt64)
return epoch, nil
}

func GetCmdQueryTotalRewardByEpoch() *cobra.Command {
cmd := &cobra.Command{
Use: "total-reward [flags]",
Short: "Query total reward by epoch",
Long: strings.TrimSpace(
fmt.Sprintf(`Query total reward by epoch.`),
),

RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

epochStr := viper.GetString(FlagEpoch)
epoch, err := checkFlagEpoch(epochStr)
if err != nil {
return err
}

result, err := queryClient.TotalRewardByEpoch(cmd.Context(), &types.QueryTotalRewardByEpochRequest{
Epoch: epoch.Int64(),
})
if err != nil {
return err
}

return clientCtx.PrintProto(result)
},
}
cmd.Flags().AddFlagSet(flagSetEpoch())
_ = cmd.MarkFlagRequired(FlagEpoch)

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
32 changes: 32 additions & 0 deletions x/pot/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
r.HandleFunc("/pot/params", potParamsHandlerFn(clientCtx, types.QueryPotParams)).Methods("GET")
r.HandleFunc("/pot/total-mined-token", getTotalMinedTokenHandlerFn(clientCtx, types.QueryTotalMinedToken)).Methods("GET")
r.HandleFunc("/pot/circulation-supply", getCirculationSupplyHandlerFn(clientCtx, types.QueryCirculationSupply)).Methods("GET")
r.HandleFunc("/pot/total-reward/{epoch}", getTotalRewardByEpochHandlerFn(clientCtx, types.QueryTotalRewardByEpoch)).Methods("GET")
}

// GET request handler to query params of POT module
Expand Down Expand Up @@ -227,3 +228,34 @@ func getCirculationSupplyHandlerFn(clientCtx client.Context, queryPath string) h
rest.PostProcessResponse(w, cliCtx, res)
}
}

func getTotalRewardByEpochHandlerFn(clientCtx client.Context, queryPath string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
}
epochStr := mux.Vars(r)["epoch"]
epoch, ok := sdk.NewIntFromString(epochStr)
if !ok {
return
}

params := types.NewQueryTotalRewardByEpochParams(epoch)
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
if err != nil {
rest.PostProcessResponse(w, cliCtx, err.Error())
return
}

route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, queryPath)
res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
rest.PostProcessResponse(w, cliCtx, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
Loading

0 comments on commit dab11c7

Please sign in to comment.