Skip to content

Commit

Permalink
address lints
Browse files Browse the repository at this point in the history
  • Loading branch information
wlawt committed Apr 30, 2024
1 parent 052bda2 commit d96a97f
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 435 deletions.
10 changes: 5 additions & 5 deletions chain/mock_action.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions cli/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (h *Handler) Spam(
}
if !result.Success {
// Should never happen
return fmt.Errorf("%w: %s", ErrTxFailed, result.Output)
return fmt.Errorf("%w: %s", ErrTxFailed, result.Outputs)
}
}
var recipientFunc func() (*PrivateKey, error)
Expand Down Expand Up @@ -446,7 +446,7 @@ func (h *Handler) Spam(
}
if !result.Success {
// Should never happen
return fmt.Errorf("%w: %s", ErrTxFailed, result.Output)
return fmt.Errorf("%w: %s", ErrTxFailed, result.Outputs)
}
}
utils.Outf(
Expand Down Expand Up @@ -492,7 +492,11 @@ func startIssuer(cctx context.Context, issuer *txIssuer) {
if result.Success {
confirmedTxs++
} else {
utils.Outf("{{orange}}on-chain tx failure:{{/}} %s %t\n", string(result.Output), result.Success)
for i := 0; i < len(result.Outputs); i++ {
for j := 0; j < len(result.Outputs[i]); j++ {
utils.Outf("{{orange}}on-chain tx failure:{{/}} %s %t\n", string(result.Outputs[i][j]), result.Success)
}
}
}
} else {
// We can't error match here because we receive it over the wire.
Expand Down
2 changes: 1 addition & 1 deletion examples/morpheusvm/cmd/morpheus-cli/cmd/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ var setKeyCmd = &cobra.Command{
},
}

func lookupKeyBalance(addr codec.Address, uri string, networkID uint32, chainID ids.ID, _ ids.ID) error {
func lookupKeyBalance(addr codec.Address, uri string, networkID uint32, chainID ids.ID, _ codec.LID) error {
_, err := handler.GetBalance(context.TODO(), brpc.NewJSONRPCClient(uri, networkID, chainID), addr)
return err
}
Expand Down
46 changes: 25 additions & 21 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,32 @@ func sendAndWait(
}

func handleTx(tx *chain.Transaction, result *chain.Result) {
summaryStr := string(result.Output)
actor := tx.Auth.Actor()
status := "❌"
if result.Success {
status = "✅"
for _, action := range tx.Actions {
switch act := action.(type) { //nolint:gocritic
case *actions.Transfer:
summaryStr = fmt.Sprintf("%s %s -> %s", utils.FormatBalance(act.Value, consts.Decimals), consts.Symbol, codec.MustAddressBech32(consts.HRP, act.To))
for i := 0; i < len(result.Outputs); i++ {
for j := 0; j < len(result.Outputs[i]); j++ {
summaryStr := string(result.Outputs[i][j])
actor := tx.Auth.Actor()
status := "❌"
if result.Success {
status = "✅"
for _, action := range tx.Actions {
switch act := action.(type) { //nolint:gocritic
case *actions.Transfer:
summaryStr = fmt.Sprintf("%s %s -> %s", utils.FormatBalance(act.Value, consts.Decimals), consts.Symbol, codec.MustAddressBech32(consts.HRP, act.To))
}
}
}
utils.Outf(
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}summary (%s):{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
status,
tx.ID(),
codec.MustAddressBech32(consts.HRP, actor),
reflect.TypeOf(tx.Actions),
summaryStr,
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
utils.FormatBalance(result.Fee, consts.Decimals),
consts.Symbol,
cli.ParseDimensions(result.Consumed),
)
}
}
utils.Outf(
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}summary (%s):{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
status,
tx.ID(),
codec.MustAddressBech32(consts.HRP, actor),
reflect.TypeOf(tx.Actions),
summaryStr,
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
utils.FormatBalance(result.Fee, consts.Decimals),
consts.Symbol,
cli.ParseDimensions(result.Consumed),
)
}
6 changes: 5 additions & 1 deletion examples/morpheusvm/tests/load/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ var _ = ginkgo.Describe("load tests vm", func() {
for _, result := range blk.Results() {
if !result.Success {
unitPrices, _ := instances[0].cli.UnitPrices(context.Background(), false)
fmt.Println("tx failed", "unit prices:", unitPrices, "consumed:", result.Consumed, "fee:", result.Fee, "output:", string(result.Output))
for i := 0; i < len(result.Outputs); i++ {
for j := 0; j < len(result.Outputs[i]); j++ {
fmt.Println("tx failed", "unit prices:", unitPrices, "consumed:", result.Consumed, "fee:", result.Fee, "output:", string(result.Outputs[i][j]))
}
}
}
gomega.Ω(result.Success).Should(gomega.BeTrue())
}
Expand Down
160 changes: 82 additions & 78 deletions examples/tokenvm/cmd/token-cli/cmd/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,88 +57,92 @@ func sendAndWait(
}

func handleTx(c *trpc.JSONRPCClient, tx *chain.Transaction, result *chain.Result) {
summaryStr := string(result.Output)
actor := tx.Auth.Actor()
status := "❌"
if result.Success {
status = "✅"
for i, act := range tx.Actions {
switch action := act.(type) {
case *actions.CreateAsset:
assetID := action.GetActionID(uint8(i), tx.ID())
summaryStr = fmt.Sprintf("assetID: %s symbol: %s decimals: %d metadata: %s", assetID, action.Symbol, action.Decimals, action.Metadata)
case *actions.MintAsset:
_, symbol, decimals, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
amountStr := utils.FormatBalance(action.Value, decimals)
summaryStr = fmt.Sprintf("%s %s -> %s", amountStr, symbol, codec.MustAddressBech32(tconsts.HRP, action.To))
case *actions.BurnAsset:
summaryStr = fmt.Sprintf("%d %s -> 🔥", action.Value, action.Asset)
for i := 0; i < len(result.Outputs); i++ {
for j := 0; j < len(result.Outputs[i]); j++ {
summaryStr := string(result.Outputs[i][j])
actor := tx.Auth.Actor()
status := "❌"
if result.Success {
status = "✅"
for i, act := range tx.Actions {
switch action := act.(type) {
case *actions.CreateAsset:
assetID := action.GetActionID(uint8(i), tx.ID())
summaryStr = fmt.Sprintf("assetID: %s symbol: %s decimals: %d metadata: %s", assetID, action.Symbol, action.Decimals, action.Metadata)
case *actions.MintAsset:
_, symbol, decimals, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
amountStr := utils.FormatBalance(action.Value, decimals)
summaryStr = fmt.Sprintf("%s %s -> %s", amountStr, symbol, codec.MustAddressBech32(tconsts.HRP, action.To))
case *actions.BurnAsset:
summaryStr = fmt.Sprintf("%d %s -> 🔥", action.Value, action.Asset)

case *actions.Transfer:
_, symbol, decimals, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
amountStr := utils.FormatBalance(action.Value, decimals)
summaryStr = fmt.Sprintf("%s %s -> %s", amountStr, symbol, codec.MustAddressBech32(tconsts.HRP, action.To))
if len(action.Memo) > 0 {
summaryStr += fmt.Sprintf(" (memo: %s)", action.Memo)
}
case *actions.Transfer:
_, symbol, decimals, _, _, _, err := c.Asset(context.TODO(), action.Asset, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
amountStr := utils.FormatBalance(action.Value, decimals)
summaryStr = fmt.Sprintf("%s %s -> %s", amountStr, symbol, codec.MustAddressBech32(tconsts.HRP, action.To))
if len(action.Memo) > 0 {
summaryStr += fmt.Sprintf(" (memo: %s)", action.Memo)
}

case *actions.CreateOrder:
_, inSymbol, inDecimals, _, _, _, err := c.Asset(context.TODO(), action.In, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
inTickStr := utils.FormatBalance(action.InTick, inDecimals)
_, outSymbol, outDecimals, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
outTickStr := utils.FormatBalance(action.OutTick, outDecimals)
supplyStr := utils.FormatBalance(action.Supply, outDecimals)
summaryStr = fmt.Sprintf("%s %s -> %s %s (supply: %s %s)", inTickStr, inSymbol, outTickStr, outSymbol, supplyStr, outSymbol)
case *actions.FillOrder:
or, _ := actions.UnmarshalOrderResult(result.Output)
_, inSymbol, inDecimals, _, _, _, err := c.Asset(context.TODO(), action.In, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
inAmtStr := utils.FormatBalance(or.In, inDecimals)
_, outSymbol, outDecimals, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
case *actions.CreateOrder:
_, inSymbol, inDecimals, _, _, _, err := c.Asset(context.TODO(), action.In, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
inTickStr := utils.FormatBalance(action.InTick, inDecimals)
_, outSymbol, outDecimals, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
outTickStr := utils.FormatBalance(action.OutTick, outDecimals)
supplyStr := utils.FormatBalance(action.Supply, outDecimals)
summaryStr = fmt.Sprintf("%s %s -> %s %s (supply: %s %s)", inTickStr, inSymbol, outTickStr, outSymbol, supplyStr, outSymbol)
case *actions.FillOrder:
or, _ := actions.UnmarshalOrderResult(result.Outputs[i][j])
_, inSymbol, inDecimals, _, _, _, err := c.Asset(context.TODO(), action.In, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
inAmtStr := utils.FormatBalance(or.In, inDecimals)
_, outSymbol, outDecimals, _, _, _, err := c.Asset(context.TODO(), action.Out, true)
if err != nil {
utils.Outf("{{red}}could not fetch asset info:{{/}} %v", err)
return
}
outAmtStr := utils.FormatBalance(or.Out, outDecimals)
remainingStr := utils.FormatBalance(or.Remaining, outDecimals)
summaryStr = fmt.Sprintf(
"%s %s -> %s %s (remaining: %s %s)",
inAmtStr, inSymbol, outAmtStr, outSymbol, remainingStr, outSymbol,
)
case *actions.CloseOrder:
summaryStr = fmt.Sprintf("orderID: %s", action.Order)
}
}
outAmtStr := utils.FormatBalance(or.Out, outDecimals)
remainingStr := utils.FormatBalance(or.Remaining, outDecimals)
summaryStr = fmt.Sprintf(
"%s %s -> %s %s (remaining: %s %s)",
inAmtStr, inSymbol, outAmtStr, outSymbol, remainingStr, outSymbol,
)
case *actions.CloseOrder:
summaryStr = fmt.Sprintf("orderID: %s", action.Order)
}
utils.Outf(
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}summary (%s):{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
status,
tx.ID(),
codec.MustAddressBech32(tconsts.HRP, actor),
reflect.TypeOf(tx.Actions),
summaryStr,
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
utils.FormatBalance(result.Fee, tconsts.Decimals),
tconsts.Symbol,
cli.ParseDimensions(result.Consumed),
)
}
}
utils.Outf(
"%s {{yellow}}%s{{/}} {{yellow}}actor:{{/}} %s {{yellow}}summary (%s):{{/}} [%s] {{yellow}}fee (max %.2f%%):{{/}} %s %s {{yellow}}consumed:{{/}} [%s]\n",
status,
tx.ID(),
codec.MustAddressBech32(tconsts.HRP, actor),
reflect.TypeOf(tx.Actions),
summaryStr,
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
utils.FormatBalance(result.Fee, tconsts.Decimals),
tconsts.Symbol,
cli.ParseDimensions(result.Consumed),
)
}
Loading

0 comments on commit d96a97f

Please sign in to comment.