Skip to content

Commit

Permalink
Merge pull request #6618 from filecoin-project/feat/gateway-version
Browse files Browse the repository at this point in the history
gateway: Add support for Version method
  • Loading branch information
magik6k committed Jun 28, 2021
2 parents 49a709a + c1303f1 commit ba7e730
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ type Gateway interface {
StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*MsgLookup, error)
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*MsgLookup, error)
WalletBalance(context.Context, address.Address) (types.BigInt, error)
Version(context.Context) (APIVersion, error)
}
10 changes: 10 additions & 0 deletions api/proxy_gen.go

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

1 change: 1 addition & 0 deletions api/v0api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Gateway interface {
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error)
StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*api.MsgLookup, error)
WalletBalance(context.Context, address.Address) (types.BigInt, error)
Version(context.Context) (api.APIVersion, error)
}

var _ Gateway = *new(FullNode)
10 changes: 10 additions & 0 deletions api/v0api/proxy_gen.go

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

21 changes: 21 additions & 0 deletions api/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ func Wrap(proxyT, wrapperT, impl interface{}) interface{} {
}))
}

for i := 0; i < proxy.Elem().NumField(); i++ {
if proxy.Elem().Type().Field(i).Name == "Internal" {
continue
}

subProxy := proxy.Elem().Field(i).FieldByName("Internal")
for i := 0; i < ri.NumMethod(); i++ {
mt := ri.Type().Method(i)
if subProxy.FieldByName(mt.Name).Kind() == reflect.Invalid {
continue
}

fn := ri.Method(i)
of := subProxy.FieldByName(mt.Name)

subProxy.FieldByName(mt.Name).Set(reflect.MakeFunc(of.Type(), func(args []reflect.Value) (results []reflect.Value) {
return fn.Call(args)
}))
}
}

wp := reflect.New(reflect.TypeOf(wrapperT).Elem())
wp.Elem().Field(0).Set(proxy)
return wp.Interface()
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions gateway/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,19 @@ func (m *mockGatewayDepsAPI) StateWaitMsgLimited(ctx context.Context, msg cid.Ci
func (m *mockGatewayDepsAPI) StateReadState(ctx context.Context, act address.Address, ts types.TipSetKey) (*api.ActorState, error) {
panic("implement me")
}

func (m *mockGatewayDepsAPI) Version(context.Context) (api.APIVersion, error) {
return api.APIVersion{
APIVersion: api.FullAPIVersion1,
}, nil
}

func TestGatewayVersion(t *testing.T) {
ctx := context.Background()
mock := &mockGatewayDepsAPI{}
a := NewNode(mock, DefaultLookbackCap, DefaultStateWaitLookbackLimit)

v, err := a.Version(ctx)
require.NoError(t, err)
require.Equal(t, api.FullAPIVersion1, v.APIVersion)
}

0 comments on commit ba7e730

Please sign in to comment.