@@ -9,50 +9,33 @@ import (
99 "errors"
1010 "fmt"
1111
12- "github.com/vechain/thor/v2/api"
13-
1412 "github.com/ethereum/go-ethereum/common/hexutil"
1513 "github.com/ethereum/go-ethereum/common/math"
14+ "github.com/vechain/thor/v2/api"
1615 "github.com/vechain/thor/v2/thor"
1716 "github.com/vechain/thor/v2/thorclient"
1817)
1918
20- // CallBuilder is the interface for read operations.
21- type CallBuilder interface {
22- // AtRevision sets the revision for the call.
23- AtRevision (rev string ) CallBuilder
24-
25- // Caller sets the caller for the simulation.
26- Caller (caller * thor.Address ) CallBuilder
27-
28- // ExecuteInto unpacks the result into the provided interface.
29- ExecuteInto (result any ) error
30-
31- // Execute performs the call and returns the raw result.
32- Execute () (* api.CallResult , error )
33- }
34-
35- // callBuilder is the concrete implementation of CallBuilder.
36- type callBuilder struct {
37- op * methodBuilder
19+ type CallBuilder struct {
20+ op * MethodBuilder
3821 rev string
3922 caller * thor.Address
4023}
4124
4225// AtRevision implements CallBuilder.AtRevision.
43- func (b * callBuilder ) AtRevision (rev string ) CallBuilder {
26+ func (b * CallBuilder ) AtRevision (rev string ) * CallBuilder {
4427 b .rev = rev
4528 return b
4629}
4730
4831// Caller implements CallBuilder.AtRevision.
49- func (b * callBuilder ) Caller (caller * thor.Address ) CallBuilder {
32+ func (b * CallBuilder ) Caller (caller * thor.Address ) * CallBuilder {
5033 b .caller = caller
5134 return b
5235}
5336
5437// ExecuteInto implements CallBuilder.Into.
55- func (b * callBuilder ) ExecuteInto (result any ) error {
38+ func (b * CallBuilder ) ExecuteInto (result any ) error {
5639 method , ok := b .op .contract .abi .Methods [b .op .method ]
5740 if ! ok {
5841 return errors .New ("method not found: " + b .op .method )
@@ -72,7 +55,7 @@ func (b *callBuilder) ExecuteInto(result any) error {
7255}
7356
7457// Execute implements CallBuilder.Execute.
75- func (b * callBuilder ) Execute () (* api.CallResult , error ) {
58+ func (b * CallBuilder ) Execute () (* api.CallResult , error ) {
7659 // Build the clause
7760 clause , err := b .op .Clause ()
7861 if err != nil {
@@ -100,24 +83,25 @@ func (b *callBuilder) Execute() (*api.CallResult, error) {
10083 return nil , fmt .Errorf ("expected 1 result, got %d" , len (res ))
10184 }
10285
103- if res [0 ].Reverted {
86+ result := res [0 ]
87+ if result .Reverted {
10488 message := "contract call reverted"
105- if res [ 0 ] .Data != "" {
106- decoded , err := hexutil .Decode (res [ 0 ] .Data )
89+ if result .Data != "" {
90+ decoded , err := hexutil .Decode (result .Data )
10791 if err != nil {
108- return nil , fmt .Errorf ("failed to decode revert data: %w" , err )
92+ return result , fmt .Errorf ("failed to decode revert data: %w" , err )
10993 }
11094 revertReason , err := UnpackRevert (decoded )
11195 if err == nil {
11296 message = fmt .Sprintf ("contract call reverted: %s" , revertReason )
11397 }
11498 }
115- return nil , errors .New (message )
99+ return result , errors .New (message )
116100 }
117101
118- if res [ 0 ] .VMError != "" {
119- return nil , fmt .Errorf ("VM error: %s" , res [ 0 ] .VMError )
102+ if result .VMError != "" {
103+ return nil , fmt .Errorf ("VM error: %s" , result .VMError )
120104 }
121105
122- return res [ 0 ] , nil
106+ return result , nil
123107}
0 commit comments