Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #518 from vegaprotocol/release/v0.13.2
Browse files Browse the repository at this point in the history
Release version 0.13.2
  • Loading branch information
jeremyletang authored Mar 22, 2022
2 parents 0991a86 + 81665ff commit deed8fa
Show file tree
Hide file tree
Showing 22 changed files with 439 additions and 227 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,30 @@
- [](https://github.com/vegaprotocol/vegawallet/pull/) -

### 🛠 Improvements
- [496](https://github.com/vegaprotocol/vegawallet/pull/496) - Return tx in /api/v1/command response
- [](https://github.com/vegaprotocol/vegawallet/pull/) -

### 🔥 Removal
- [](https://github.com/vegaprotocol/vegawallet/pull/) -

### 🐛 Fixes
- [](https://github.com/vegaprotocol/vegawallet/pull/) -


## 0.13.2

### 🚨 Breaking changes
- [504](https://github.com/vegaprotocol/vegawallet/pull/504) - Add support for proof of work sent from the wallet as part of a transaction
- [507](https://github.com/vegaprotocol/vegawallet/issues/507) - Flag `--level` in service run removed

### 🛠 Improvements
- [508](https://github.com/vegaprotocol/vegawallet/issues/508) - Introduce a command to list the service endpoints
- [507](https://github.com/vegaprotocol/vegawallet/issues/507) - Redirect logs from command service run to a file
- [516](https://github.com/vegaprotocol/vegawallet/issues/516) - Update protos for market update proposal

### 🐛 Fixes
- [502](https://github.com/vegaprotocol/vegawallet/pull/502) - Unwrap properly transfer and cancel transfer commands


## 0.13.1

### 🛠 Improvements
Expand Down
8 changes: 6 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pipeline {
options {
skipDefaultCheckout true
timestamps()
timeout(time: 30, unit: 'MINUTES')
timeout(time: 45, unit: 'MINUTES')
}
parameters {
string( name: 'VEGA_CORE_BRANCH', defaultValue: '',
Expand Down Expand Up @@ -48,8 +48,12 @@ pipeline {
steps {
cleanWs()
sh 'printenv'
echo "${params}"
echo "params=${params}"
echo "isPRBuild=${isPRBuild()}"
script {
params = pr.injectPRParams()
}
echo "params (after injection)=${params}"
}
}

Expand Down
28 changes: 23 additions & 5 deletions cmd/command_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"io"

api "code.vegaprotocol.io/protos/vega/api/v1"
commandspb "code.vegaprotocol.io/protos/vega/commands/v1"
walletpb "code.vegaprotocol.io/protos/vega/wallet/v1"
"code.vegaprotocol.io/shared/libs/crypto"
vglog "code.vegaprotocol.io/shared/libs/zap"
"code.vegaprotocol.io/vegawallet/cmd/cli"
"code.vegaprotocol.io/vegawallet/cmd/flags"
Expand Down Expand Up @@ -210,7 +212,7 @@ type SendCommandRequest struct {
}

func SendCommand(w io.Writer, rf *RootFlags, req *SendCommandRequest) error {
log, err := Build(rf.Output, req.LogLevel)
log, err := BuildLogger(rf.Output, req.LogLevel)
if err != nil {
return err
}
Expand Down Expand Up @@ -260,21 +262,37 @@ func SendCommand(w io.Writer, rf *RootFlags, req *SendCommandRequest) error {
defer cancelFn()

log.Info("retrieving block height")
blockHeight, err := forwarder.LastBlockHeight(ctx)
blockData, cltIdx, err := forwarder.LastBlockHeightAndHash(ctx)
if err != nil {
return fmt.Errorf("couldn't get last block height: %w", err)
}
log.Info(fmt.Sprintf("last block height found: %d", blockHeight))

tx, err := handler.SignTx(req.Wallet, req.Request, blockHeight)
log.Info(fmt.Sprintf("last block height found: %d", blockData.Height))

tx, err := handler.SignTx(req.Wallet, req.Request, blockData.Height)
if err != nil {
log.Error("couldn't sign transaction", zap.Error(err))
return fmt.Errorf("couldn't sign transaction: %w", err)
}

log.Info("transaction successfully signed", zap.String("signature", tx.Signature.Value))

txHash, err := forwarder.SendTx(ctx, tx, api.SubmitTransactionRequest_TYPE_ASYNC)
// generate a random transaction hash
tid := crypto.RandomHash()

// generate proof of work for the block hash, transaction id and given difficulty required and supported hash function
powNonce, _, err := crypto.PoW(blockData.Hash, tid, uint(blockData.SpamPowDifficulty), blockData.SpamPowHashFunction)
if err != nil {
return fmt.Errorf("couldn't generate proof of work for last block height: %w", err)
}
tx.Pow = &commandspb.ProofOfWork{
Tid: tid,
Nonce: powNonce,
}

log.Info("calculated proof of work for transaction with signature", zap.String("signature", tx.Signature.Value))

txHash, err := forwarder.SendTx(ctx, tx, api.SubmitTransactionRequest_TYPE_ASYNC, cltIdx)
if err != nil {
log.Error("couldn't send transaction", zap.Error(err))
return fmt.Errorf("couldn't send transaction: %w", err)
Expand Down
35 changes: 34 additions & 1 deletion cmd/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package cmd

import (
"fmt"
"os"
"time"

"code.vegaprotocol.io/shared/paths"
"code.vegaprotocol.io/vegawallet/cmd/flags"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -53,7 +56,37 @@ func DefaultConfig() zap.Config {
}
}

func Build(output, level string) (*zap.Logger, error) {
func BuildJSONLogger(level string, logsDir paths.StatePath) (*zap.Logger, error) {
cfg := DefaultConfig()

l, err := getLevel(level)
if err != nil {
return nil, err
}

cfg.Level = zap.NewAtomicLevelAt(*l)

pid := os.Getpid()
date := time.Now().UTC().Format("2006-01-02-15-04-05")
pathSuffix := fmt.Sprintf("%d-%s.log", pid, date)

logFile := paths.JoinStatePath(logsDir, pathSuffix)
appLogPath, err := paths.CreateDefaultStatePathFor(logFile)
if err != nil {
return nil, fmt.Errorf("failed getting path for %s: %w", logFile, err)
}

cfg.OutputPaths = []string{appLogPath}
cfg.ErrorOutputPaths = []string{appLogPath}

log, err := cfg.Build()
if err != nil {
return nil, fmt.Errorf("couldn't create logger: %w", err)
}
return log, nil
}

func BuildLogger(output, level string) (*zap.Logger, error) {
cfg := DefaultConfig()

l, err := getLevel(level)
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ func NewCmdService(w io.Writer, rf *RootFlags) *cobra.Command {
}

cmd.AddCommand(NewCmdRunService(w, rf))
cmd.AddCommand(NewCmdListEndpoints(w, rf))
return cmd
}
145 changes: 145 additions & 0 deletions cmd/service_endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package cmd

import (
"fmt"
"io"
"os"
"text/template"

"code.vegaprotocol.io/vegawallet/cmd/cli"

"code.vegaprotocol.io/shared/paths"
"code.vegaprotocol.io/vegawallet/cmd/flags"
"code.vegaprotocol.io/vegawallet/cmd/printer"
netstore "code.vegaprotocol.io/vegawallet/network/store/v1"
"github.com/spf13/cobra"
)

const startupT = ` # Authentication
- login: POST {{.WalletServiceLocalAddress}}/api/v1/auth/token
- logout: DELETE {{.WalletServiceLocalAddress}}/api/v1/auth/token
# Network management
- network: GET {{.WalletServiceLocalAddress}}/api/v1/network
# Wallet management
- create a wallet: POST {{.WalletServiceLocalAddress}}/api/v1/wallets
- import a wallet: POST {{.WalletServiceLocalAddress}}/api/v1/wallets/import
# Key pair management
- generate a key pair: POST {{.WalletServiceLocalAddress}}/api/v1/keys
- list keys: GET {{.WalletServiceLocalAddress}}/api/v1/keys
- describe a key pair: GET {{.WalletServiceLocalAddress}}/api/v1/keys/:keyid
- taint a key pair: PUT {{.WalletServiceLocalAddress}}/api/v1/keys/:keyid/taint
- annotate a key pair: PUT {{.WalletServiceLocalAddress}}/api/v1/keys/:keyid/metadata
# Commands
- sign a command: POST {{.WalletServiceLocalAddress}}/api/v1/command
- sign a command (sync): POST {{.WalletServiceLocalAddress}}/api/v1/command/sync
- sign a command (commit): POST {{.WalletServiceLocalAddress}}/api/v1/command/commit
- sign data: POST {{.WalletServiceLocalAddress}}/api/v1/sign
- verify data: POST {{.WalletServiceLocalAddress}}/api/v1/verify
# Information
- get service status: GET {{.WalletServiceLocalAddress}}/api/v1/status
- get the version: GET {{.WalletServiceLocalAddress}}/api/v1/version
`

var (
listEndpointsLong = cli.LongDesc(`
List the Vega wallet service HTTP endpoints
`)

listEndpointsExample = cli.Examples(`
# List service endpoints
vegawallet endpoints --network NETWORK
`)
)

type ListEndpointsHandler func(io.Writer, *RootFlags, *ListEndpointsFlags) error

func NewCmdListEndpoints(w io.Writer, rf *RootFlags) *cobra.Command {
return BuildCmdListEndpoints(w, ListEndpoints, rf)
}

func BuildCmdListEndpoints(w io.Writer, handler ListEndpointsHandler, rf *RootFlags) *cobra.Command {
f := &ListEndpointsFlags{}

cmd := &cobra.Command{
Use: "endpoints",
Short: "List endpoints",
Long: listEndpointsLong,
Example: listEndpointsExample,
RunE: func(_ *cobra.Command, _ []string) error {
if err := f.Validate(); err != nil {
return err
}

if err := handler(w, rf, f); err != nil {
return err
}

return nil
},
}

cmd.Flags().StringVarP(&f.Network,
"network", "n",
"",
"Network configuration to use",
)

return cmd
}

type ListEndpointsFlags struct {
Network string
}

func (f *ListEndpointsFlags) Validate() error {
if len(f.Network) == 0 {
return flags.FlagMustBeSpecifiedError("network")
}

return nil
}

func ListEndpoints(w io.Writer, rf *RootFlags, f *ListEndpointsFlags) error {
p := printer.NewInteractivePrinter(w)

vegaPaths := paths.New(rf.Home)
netStore, err := netstore.InitialiseStore(vegaPaths)
if err != nil {
return fmt.Errorf("couldn't initialise network store: %w", err)
}

cfg, err := netStore.GetNetwork(f.Network)
if err != nil {
return fmt.Errorf("couldn't initialise network store: %w", err)
}

serviceHost := fmt.Sprintf("http://%v:%v", cfg.Host, cfg.Port)

p.BlueArrow().InfoText("Available endpoints").NextLine()
printServiceEndpoints(serviceHost)
p.NextLine()

return nil
}

func printServiceEndpoints(serviceHost string) {
params := struct {
WalletServiceLocalAddress string
}{
WalletServiceLocalAddress: serviceHost,
}

tmpl, err := template.New("wallet-cmdline").Parse(startupT)
if err != nil {
panic(err)
}
err = tmpl.Execute(os.Stdout, params)
if err != nil {
panic(err)
}
}
Loading

0 comments on commit deed8fa

Please sign in to comment.