2
2
package medley
3
3
4
4
import (
5
- "bytes"
6
5
"context"
7
- "encoding/gob"
8
6
"errors"
9
- "fmt"
10
7
"math"
11
8
"os"
12
9
"strings"
13
10
"time"
14
11
15
- "github.com/ethereum/go-ethereum"
16
12
"github.com/ethereum/go-ethereum/common"
17
- "github.com/ethereum/go-ethereum/core/types"
18
- "github.com/ethereum/go-ethereum/ethclient"
19
13
pkgErrors "github.com/pkg/errors"
20
14
"github.com/spf13/cobra"
21
15
"github.com/spf13/pflag"
@@ -51,49 +45,6 @@ func Sleep(ctx context.Context, d time.Duration) {
51
45
}
52
46
}
53
47
54
- // WaitMined waits for a transaction to be mined and returns its receipt. It's a replacement for
55
- // bind.WaitMined which doesn't seem to work with Ganache in some cases.
56
- func WaitMined (ctx context.Context , client * ethclient.Client , txHash common.Hash ) (* types.Receipt , error ) {
57
- for {
58
- receipt , err := client .TransactionReceipt (ctx , txHash )
59
- if err == ethereum .NotFound {
60
- Sleep (ctx , receiptPollInterval )
61
- continue
62
- }
63
- if err != nil {
64
- return nil , err
65
- }
66
- return receipt , nil
67
- }
68
- }
69
-
70
- func WaitMinedMany (ctx context.Context , client * ethclient.Client , txHashes []common.Hash ) ([]* types.Receipt , error ) {
71
- defer fmt .Print ("\n " )
72
- var res []* types.Receipt
73
-
74
- failedTxs := []int {}
75
- for i , txHash := range txHashes {
76
- receipt , err := WaitMined (ctx , client , txHash )
77
- if err != nil {
78
- return res , err
79
- }
80
- res = append (res , receipt )
81
- if receipt .Status != 1 {
82
- fmt .Print ("X" )
83
- failedTxs = append (failedTxs , i )
84
- } else {
85
- fmt .Print ("." )
86
- }
87
- }
88
-
89
- if len (failedTxs ) > 0 {
90
- firstFailed := failedTxs [0 ]
91
- return res , pkgErrors .Errorf ("some txs have failed, the first being %s" , txHashes [firstFailed ])
92
- }
93
-
94
- return res , nil
95
- }
96
-
97
48
// EnsureUniqueAddresses makes sure the slice of addresses doesn't contain duplicate addresses.
98
49
func EnsureUniqueAddresses (addrs []common.Address ) error {
99
50
seen := make (map [common.Address ]struct {})
@@ -106,35 +57,6 @@ func EnsureUniqueAddresses(addrs []common.Address) error {
106
57
return nil
107
58
}
108
59
109
- // DedupAddresses returns a new slice containing only unique addresses.
110
- func DedupAddresses (addrs []common.Address ) []common.Address {
111
- var res []common.Address
112
- seen := make (map [common.Address ]struct {})
113
-
114
- for _ , a := range addrs {
115
- if _ , ok := seen [a ]; ok {
116
- continue
117
- }
118
- seen [a ] = struct {}{}
119
- res = append (res , a )
120
- }
121
-
122
- return res
123
- }
124
-
125
- // CloneWithGob clones the given object by serializing/deserializing with gob.
126
- func CloneWithGob (src , dst interface {}) {
127
- buff := bytes.Buffer {}
128
- err := gob .NewEncoder (& buff ).Encode (src )
129
- if err != nil {
130
- panic (err )
131
- }
132
- err = gob .NewDecoder (& buff ).Decode (dst )
133
- if err != nil {
134
- panic (err )
135
- }
136
- }
137
-
138
60
func normName (s string ) string {
139
61
return strings .ToUpper (strings .ReplaceAll (s , "-" , "_" ))
140
62
}
0 commit comments