forked from block-vision/sui-go-sdk
/
base_api.go
34 lines (29 loc) · 871 Bytes
/
base_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) BlockVision, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package sui
import (
"context"
"errors"
"github.com/fluidity-money/sui-go-sdk/common/httpconn"
"github.com/tidwall/gjson"
)
type IBaseAPI interface {
SuiCall(ctx context.Context, method string, params ...interface{}) (interface{}, error)
}
type suiBaseImpl struct {
conn *httpconn.HttpConn
}
// SuiCall send customized request to Sui Node endpoint.
func (s *suiBaseImpl) SuiCall(ctx context.Context, method string, params ...interface{}) (interface{}, error) {
resp, err := s.conn.Request(ctx, httpconn.Operation{
Method: method,
Params: params,
})
if err != nil {
return nil, err
}
if gjson.ParseBytes(resp).Get("error").Exists() {
return nil, errors.New(gjson.ParseBytes(resp).Get("error").String())
}
return gjson.ParseBytes(resp).String(), nil
}