• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lmittmann / w3 / 7997657861

22 Feb 2024 12:42AM UTC coverage: 74.867%. Remained the same
7997657861

Pull #113

github

web-flow
build(deps): bump github.com/ethereum/go-ethereum in /examples

Bumps [github.com/ethereum/go-ethereum](https://github.com/ethereum/go-ethereum) from 1.13.11 to 1.13.13.
- [Release notes](https://github.com/ethereum/go-ethereum/releases)
- [Commits](https://github.com/ethereum/go-ethereum/compare/v1.13.11...v1.13.13)

---
updated-dependencies:
- dependency-name: github.com/ethereum/go-ethereum
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #113: build(deps): bump github.com/ethereum/go-ethereum from 1.13.11 to 1.13.13 in /examples

1966 of 2626 relevant lines covered (74.87%)

1349.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/module/factory.go
1
package module
2

3
import (
4
        "bytes"
5
        "encoding/json"
6
        "math/big"
7

8
        "github.com/ethereum/go-ethereum/common/hexutil"
9
        "github.com/ethereum/go-ethereum/rpc"
10
        "github.com/lmittmann/w3/w3types"
11
)
12

13
var (
14
        null = []byte("null")
15
)
16

17
type Option[T any] func(*Factory[T])
18

19
type ArgsWrapperFunc func([]any) ([]any, error)
20

21
type RetWrapperFunc[T any] func(*T) any
22

23
type Factory[T any] struct {
24
        method string
25
        args   []any
26
        ret    *T
27

28
        argsWrapper ArgsWrapperFunc
29
        retWrapper  RetWrapperFunc[T]
30
}
31

32
func NewFactory[T any](method string, args []any, opts ...Option[T]) *Factory[T] {
×
33
        f := &Factory[T]{
×
34
                method: method,
×
35
                args:   args,
×
36

×
37
                argsWrapper: func(args []any) ([]any, error) { return args, nil },
×
38
                retWrapper:  func(ret *T) any { return ret },
×
39
        }
40
        for _, opt := range opts {
×
41
                opt(f)
×
42
        }
×
43
        return f
×
44
}
45

46
func (f Factory[T]) Returns(ret *T) w3types.RPCCaller {
×
47
        f.ret = ret
×
48
        return f
×
49
}
×
50

51
func (f Factory[T]) CreateRequest() (rpc.BatchElem, error) {
×
52
        args, err := f.argsWrapper(f.args)
×
53
        if err != nil {
×
54
                return rpc.BatchElem{}, err
×
55
        }
×
56

57
        return rpc.BatchElem{
×
58
                Method: f.method,
×
59
                Args:   args,
×
60
                Result: &json.RawMessage{},
×
61
        }, nil
×
62
}
63

64
func (f Factory[T]) HandleResponse(elem rpc.BatchElem) error {
×
65
        if err := elem.Error; err != nil {
×
66
                return err
×
67
        }
×
68

69
        ret := *(elem.Result.(*json.RawMessage))
×
70
        if len(ret) == 0 || bytes.Equal(ret, null) {
×
71
                return errNotFound
×
72
        }
×
73

74
        if err := json.Unmarshal(ret, f.retWrapper(f.ret)); err != nil {
×
75
                return err
×
76
        }
×
77
        return nil
×
78
}
79

80
func WithArgsWrapper[T any](fn ArgsWrapperFunc) Option[T] {
×
81
        return func(f *Factory[T]) {
×
82
                f.argsWrapper = fn
×
83
        }
×
84
}
85

86
func WithRetWrapper[T any](fn RetWrapperFunc[T]) Option[T] {
×
87
        return func(f *Factory[T]) {
×
88
                f.retWrapper = fn
×
89
        }
×
90
}
91

92
var (
93
        HexBigRetWrapper    RetWrapperFunc[big.Int] = func(ret *big.Int) any { return (*hexutil.Big)(ret) }
×
94
        HexUintRetWrapper   RetWrapperFunc[uint]    = func(ret *uint) any { return (*hexutil.Uint)(ret) }
×
95
        HexUint64RetWrapper RetWrapperFunc[uint64]  = func(ret *uint64) any { return (*hexutil.Uint64)(ret) }
×
96
        HexBytesRetWrapper  RetWrapperFunc[[]byte]  = func(ret *[]byte) any { return (*hexutil.Bytes)(ret) }
×
97
)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc