Skip to content

Commit

Permalink
Updated to latest master version of eos-go
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Vachon committed Mar 16, 2020
1 parent cb49086 commit 76d29d2
Show file tree
Hide file tree
Showing 83 changed files with 263 additions and 113 deletions.
3 changes: 2 additions & 1 deletion analysis/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package analysis

import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -192,7 +193,7 @@ func (a *Analyzer) analyzeAction(idx int, act *eos.Action) (err error) {
}

default:
data, err := a.API.ABIBinToJSON(act.Account, eos.Name(act.Name), act.ActionData.HexData)
data, err := a.API.ABIBinToJSON(context.Background(), act.Account, eos.Name(act.Name), act.ActionData.HexData)
if err != nil {
a.Pf("Couldn't decode ABI: %s\n", err)
a.Pf("Hex data: %s\n", hex.EncodeToString(act.ActionData.HexData))
Expand Down
14 changes: 8 additions & 6 deletions bios/bios.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bios

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
Expand Down Expand Up @@ -63,6 +64,7 @@ func (b *BIOS) Boot() error {
return err
}

ctx := context.Background()
pubKey = b.EphemeralPublicKey
privKey = b.EphemeralPrivateKey.String()

Expand All @@ -81,12 +83,12 @@ func (b *BIOS) Boot() error {
// Don't get `get_required_keys` from the blockchain, this adds
// latency.. and we KNOW the key you're going to ask :) It's the
// only key we're going to sign with anyway..
b.TargetNetAPI.SetCustomGetRequiredKeys(func(tx *eos.Transaction) (out []ecc.PublicKey, err error) {
b.TargetNetAPI.SetCustomGetRequiredKeys(func(ctx context.Context, tx *eos.Transaction) (out []ecc.PublicKey, err error) {
return append(out, pubKey), nil
})

// Store keys in wallet, to sign `SetCode` and friends..
if err := b.TargetNetAPI.Signer.ImportPrivateKey(privKey); err != nil {
if err := b.TargetNetAPI.Signer.ImportPrivateKey(ctx, privKey); err != nil {
return fmt.Errorf("ImportWIF: %s", err)
}

Expand All @@ -101,7 +103,7 @@ func (b *BIOS) Boot() error {
b.pingTargetNetwork()

b.Log.Println("In-memory keys:")
memkeys, _ := b.TargetNetAPI.Signer.AvailableKeys()
memkeys, _ := b.TargetNetAPI.Signer.AvailableKeys(ctx)
for _, key := range memkeys {
b.Log.Printf("- %s\n", key.String())
}
Expand All @@ -120,7 +122,7 @@ func (b *BIOS) Boot() error {
if len(acts) != 0 {
for idx, chunk := range ChunkifyActions(acts) {
err := Retry(25, time.Second, func() error {
_, err := b.TargetNetAPI.SignPushActions(chunk...)
_, err := b.TargetNetAPI.SignPushActions(ctx, chunk...)
if err != nil {
b.Log.Printf("r")
b.Log.Debugf("error pushing transaction for step %q, chunk %d: %s\n", step.Op, idx, err)
Expand Down Expand Up @@ -336,7 +338,7 @@ func (v ValidationErrors) Error() string {
func (b *BIOS) pingTargetNetwork() {
b.Log.Printf("Pinging target node at %q...", b.TargetNetAPI.BaseURL)
for {
info, err := b.TargetNetAPI.GetInfo()
info, err := b.TargetNetAPI.GetInfo(context.Background())
if err != nil {
b.Log.Debugf("target node error: %s\n", err)
b.Log.Printf("e")
Expand Down Expand Up @@ -376,7 +378,7 @@ func (b *BIOS) validateTargetNetwork(bootSeqMap ActionMap, bootSeq []*eos.Action
for {
time.Sleep(timeBetweenFetch)

m, err := b.TargetNetAPI.GetBlockByNum(uint32(blockHeight))
m, err := b.TargetNetAPI.GetBlockByNum(context.Background(), uint32(blockHeight))
if err != nil {
if gotSomeTx && !backOff {
backOff = true
Expand Down
29 changes: 15 additions & 14 deletions eosc/cmd/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
Expand Down Expand Up @@ -114,7 +115,7 @@ func getCoreSymbol() eos.Symbol {
}

func initCoreSymbol() error {
resp, err := getAPI().GetTableRows(eos.GetTableRowsRequest{
resp, err := getAPI().GetTableRows(context.Background(), eos.GetTableRowsRequest{
Code: "eosio",
Scope: "eosio",
Table: "rammarket",
Expand Down Expand Up @@ -178,11 +179,11 @@ func permissionsToPermissionLevels(in []string) (out []eos.PermissionLevel, err
return
}

func pushEOSCActions(api *eos.API, actions ...*eos.Action) {
pushEOSCActionsAndContextFreeActions(api, nil, actions)
func pushEOSCActions(ctx context.Context, api *eos.API, actions ...*eos.Action) {
pushEOSCActionsAndContextFreeActions(ctx, api, nil, actions)
}

func pushEOSCActionsAndContextFreeActions(api *eos.API, contextFreeActions []*eos.Action, actions []*eos.Action) {
func pushEOSCActionsAndContextFreeActions(ctx context.Context, api *eos.API, contextFreeActions []*eos.Action, actions []*eos.Action) {
for _, act := range contextFreeActions {
act.Authorization = nil
}
Expand Down Expand Up @@ -211,7 +212,7 @@ func pushEOSCActionsAndContextFreeActions(api *eos.API, contextFreeActions []*eo
opts.DelaySecs = uint32(delaySec)
}

if err := opts.FillFromChain(api); err != nil {
if err := opts.FillFromChain(ctx, api); err != nil {
fmt.Println("Error fetching tapos + chain_id from the chain (specify --offline flags for offline operations):", err)
os.Exit(1)
}
Expand All @@ -223,9 +224,9 @@ func pushEOSCActionsAndContextFreeActions(api *eos.API, contextFreeActions []*eo

tx = optionallySudoWrap(tx, opts)

signedTx, packedTx := optionallySignTransaction(tx, opts.ChainID, api, true)
signedTx, packedTx := optionallySignTransaction(ctx, tx, opts.ChainID, api, true)

optionallyPushTransaction(signedTx, packedTx, opts.ChainID, api)
optionallyPushTransaction(ctx, signedTx, packedTx, opts.ChainID, api)
}

func optionallySudoWrap(tx *eos.Transaction, opts *eos.TxOptions) *eos.Transaction {
Expand All @@ -235,7 +236,7 @@ func optionallySudoWrap(tx *eos.Transaction, opts *eos.TxOptions) *eos.Transacti
return tx
}

func optionallySignTransaction(tx *eos.Transaction, chainID eos.SHA256Bytes, api *eos.API, resetExpiration bool) (signedTx *eos.SignedTransaction, packedTx *eos.PackedTransaction) {
func optionallySignTransaction(ctx context.Context, tx *eos.Transaction, chainID eos.SHA256Bytes, api *eos.API, resetExpiration bool) (signedTx *eos.SignedTransaction, packedTx *eos.PackedTransaction) {
if !viper.GetBool("global-skip-sign") {
textSignKeys := viper.GetStringSlice("global-offline-sign-key")
if len(textSignKeys) > 0 {
Expand All @@ -246,7 +247,7 @@ func optionallySignTransaction(tx *eos.Transaction, chainID eos.SHA256Bytes, api

signKeys = append(signKeys, pubKey)
}
api.SetCustomGetRequiredKeys(func(tx *eos.Transaction) ([]ecc.PublicKey, error) {
api.SetCustomGetRequiredKeys(func(ctx context.Context, tx *eos.Transaction) ([]ecc.PublicKey, error) {
return signKeys, nil
})
}
Expand All @@ -258,7 +259,7 @@ func optionallySignTransaction(tx *eos.Transaction, chainID eos.SHA256Bytes, api
}

var err error
signedTx, packedTx, err = api.SignTransaction(tx, chainID, eos.CompressionNone)
signedTx, packedTx, err = api.SignTransaction(ctx, tx, chainID, eos.CompressionNone)
errorCheck("signing transaction", err)
} else {
tx.SetExpiration(time.Duration(viper.GetInt("global-expiration")) * time.Second)
Expand All @@ -268,7 +269,7 @@ func optionallySignTransaction(tx *eos.Transaction, chainID eos.SHA256Bytes, api
return signedTx, packedTx
}

func optionallyPushTransaction(signedTx *eos.SignedTransaction, packedTx *eos.PackedTransaction, chainID eos.SHA256Bytes, api *eos.API) {
func optionallyPushTransaction(ctx context.Context, signedTx *eos.SignedTransaction, packedTx *eos.PackedTransaction, chainID eos.SHA256Bytes, api *eos.API) {
writeTrx := viper.GetString("global-write-transaction")

if writeTrx != "" {
Expand All @@ -289,12 +290,12 @@ func optionallyPushTransaction(signedTx *eos.SignedTransaction, packedTx *eos.Pa
}

// TODO: print the traces
pushTransaction(api, packedTx, chainID)
pushTransaction(ctx, api, packedTx, chainID)
}
}

func pushTransaction(api *eos.API, packedTx *eos.PackedTransaction, chainID eos.SHA256Bytes) {
resp, err := api.PushTransaction(packedTx)
func pushTransaction(ctx context.Context, api *eos.API, packedTx *eos.PackedTransaction, chainID eos.SHA256Bytes) {
resp, err := api.PushTransaction(ctx, packedTx)
if err != nil {
if typedErr, ok := err.(eos.APIError); ok {
printError(typedErr)
Expand Down
3 changes: 2 additions & 1 deletion eosc/cmd/forumCleanProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"context"
"strconv"

"github.com/eoscanada/eos-go/forum"
Expand All @@ -26,7 +27,7 @@ var forumCleanProposalCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
4 changes: 3 additions & 1 deletion eosc/cmd/forumExpire.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package cmd

import (
"context"

"github.com/eoscanada/eos-go/forum"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -22,7 +24,7 @@ var forumExpireCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
6 changes: 4 additions & 2 deletions eosc/cmd/forumList.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"context"
"encoding/json"
"fmt"

Expand All @@ -16,6 +17,7 @@ var forumListCmd = &cobra.Command{
Short: "List forum proposals.",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
api := getAPI()
targetAccount := toAccount(viper.GetString("forum-cmd-target-contract"), "--target-contract")

Expand All @@ -26,7 +28,7 @@ var forumListCmd = &cobra.Command{
var resp *eos.GetTableRowsResp
if proposerStr != "" {
proposer = toAccount(proposerStr, "--from-proposer")
resp, err = api.GetTableRows(eos.GetTableRowsRequest{
resp, err = api.GetTableRows(ctx, eos.GetTableRowsRequest{
Code: string(targetAccount),
Scope: string(targetAccount),
Table: string("proposal"),
Expand All @@ -40,7 +42,7 @@ var forumListCmd = &cobra.Command{
errorCheck(fmt.Sprintf("unable to get list of proposals from proposer %q", proposer), err)
}
} else {
resp, err = api.GetTableRows(eos.GetTableRowsRequest{
resp, err = api.GetTableRows(ctx, eos.GetTableRowsRequest{
Code: string(targetAccount),
Scope: string(targetAccount),
Table: string("proposal"),
Expand Down
3 changes: 2 additions & 1 deletion eosc/cmd/forumPost.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"context"
"encoding/json"

"github.com/eoscanada/eos-go"
Expand Down Expand Up @@ -48,7 +49,7 @@ var forumPostCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
3 changes: 2 additions & 1 deletion eosc/cmd/forumPropose.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"context"
"errors"
"time"

Expand Down Expand Up @@ -51,7 +52,7 @@ var forumProposeCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
4 changes: 3 additions & 1 deletion eosc/cmd/forumStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package cmd

import (
"context"

"github.com/eoscanada/eos-go/forum"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -22,7 +24,7 @@ var forumStatusCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
4 changes: 3 additions & 1 deletion eosc/cmd/forumUnPost.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package cmd

import (
"context"

"github.com/eoscanada/eos-go/forum"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -22,7 +24,7 @@ var forumUnPostCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
4 changes: 3 additions & 1 deletion eosc/cmd/forumUnVote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package cmd

import (
"context"

"github.com/eoscanada/eos-go/forum"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -22,7 +24,7 @@ var forumUnVoteCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
3 changes: 2 additions & 1 deletion eosc/cmd/forumVote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cmd

import (
"context"
"fmt"
"strconv"

Expand Down Expand Up @@ -41,7 +42,7 @@ var forumVoteCmd = &cobra.Command{
action.Account = targetAccount

api := getAPI()
pushEOSCActions(api, action)
pushEOSCActions(context.Background(), api, action)
},
}

Expand Down
3 changes: 2 additions & 1 deletion eosc/cmd/getABI.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"encoding/json"
"fmt"

Expand All @@ -15,7 +16,7 @@ var getABICmd = &cobra.Command{
api := getAPI()

accountName := toAccount(args[0], "account name")
abi, err := api.GetABI(accountName)
abi, err := api.GetABI(context.Background(), accountName)
errorCheck("get ABI", err)

if !isStubABI(abi.ABI) {
Expand Down
3 changes: 2 additions & 1 deletion eosc/cmd/getAccount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"encoding/json"
"fmt"

Expand All @@ -21,7 +22,7 @@ var getAccountCmd = &cobra.Command{
api := getAPI()

accountName := toAccount(args[0], "account name")
account, err := api.GetAccount(accountName)
account, err := api.GetAccount(context.Background(), accountName)
errorCheck("get account", err)

if viper.GetBool("get-account-cmd-json") == true {
Expand Down
Loading

0 comments on commit 76d29d2

Please sign in to comment.