From 28f43ef6c1feb03bc524a33329ea1f38804dddaa Mon Sep 17 00:00:00 2001 From: billettc Date: Fri, 6 Nov 2020 11:20:48 -0500 Subject: [PATCH] replace new rpc client by alex one --- client.go | 91 -------------------------------------------- go.mod | 5 +-- go.sum | 25 ++++++++---- rpc/client.go | 94 ++++++++++++++++++++++++++++++++++------------ rpc/client_test.go | 14 ++----- 5 files changed, 94 insertions(+), 135 deletions(-) delete mode 100644 client.go diff --git a/client.go b/client.go deleted file mode 100644 index 3074ea2..0000000 --- a/client.go +++ /dev/null @@ -1,91 +0,0 @@ -package solana - -import ( - "context" - "net/http" - - "github.com/ybbus/jsonrpc" -) - -type Client struct { - rpcURL string - rpcClient jsonrpc.RPCClient - headers http.Header - - Debug bool -} - -func NewClient(rpcURL string) *Client { - rpcClient := jsonrpc.NewClient(rpcURL) - return &Client{ - rpcURL: rpcURL, - rpcClient: rpcClient, - } -} - -func (c *Client) SetHeader(k, v string) { - if c.headers == nil { - c.headers = http.Header{} - } - c.headers.Set(k, v) -} - -func (c *Client) GetBalance(ctx context.Context, publicKey string, commitment CommitmentType) (out *GetBalanceResult, err error) { - params := []interface{}{publicKey} - if commitment != "" { - params = append(params, string(commitment)) - } - - err = c.rpcClient.CallFor(&out, "getBalance", params...) - return -} - -func (c *Client) GetRecentBlockhash(ctx context.Context, commitment CommitmentType) (out *GetRecentBlockhashResult, err error) { - var params []interface{} - if commitment != "" { - params = append(params, string(commitment)) - } - - err = c.rpcClient.CallFor(&out, "getRecentBlockhash", params...) - return -} - -func (c *Client) GetSlot(ctx context.Context, commitment CommitmentType) (out GetSlotResult, err error) { - var params []interface{} - if commitment != "" { - params = append(params, string(commitment)) - } - - err = c.rpcClient.CallFor(&out, "getSlot", params...) - return -} - -func (c *Client) GetConfirmedBlock(ctx context.Context, slot uint64, encoding string) (out *GetConfirmedBlockResult, err error) { - if encoding == "" { - encoding = "json" - } - params := []interface{}{slot, encoding} - - err = c.rpcClient.CallFor(&out, "getConfirmedBlock", params...) - return -} - -func (c *Client) GetAccountInfo(ctx context.Context, publicKey string) (out *GetAccountInfoResult, err error) { - obj := map[string]interface{}{ - "encoding": "base64", - } - params := []interface{}{publicKey, obj} - - err = c.rpcClient.CallFor(&out, "getAccountInfo", params...) - return -} - -func (c *Client) GetProgramAccounts(ctx context.Context, publicKey string, opts *GetProgramAccountsOpts) (out *GetProgramAccountsResult, err error) { - params := []interface{}{publicKey} - if opts != nil { - params = append(params, opts) - } - - err = c.rpcClient.CallFor(&out, "getProgramAccounts", params...) - return -} diff --git a/go.mod b/go.mod index b898489..a294d93 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/dfuse-io/solana-go go 1.14 require ( - github.com/davecgh/go-spew v1.1.1 github.com/dfuse-io/logging v0.0.0-20200819170935-85f72399491a github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 + github.com/mafredri/cdp v0.30.0 github.com/mr-tron/base58 v1.2.0 github.com/onsi/gomega v1.10.1 // indirect github.com/pkg/errors v0.8.1 @@ -15,8 +15,7 @@ require ( github.com/stretchr/testify v1.6.1 github.com/ybbus/jsonrpc v2.1.2+incompatible go.uber.org/zap v1.15.0 - golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc + golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 google.golang.org/api v0.13.0 - gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index f6319fe..43cf471 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dfuse-io/logging v0.0.0-20200819164719-22059654dac2 h1:Hdk35RxnPyDWUHNtSSP/bVeXc7+PlKpme4aahuiJpjY= -github.com/dfuse-io/logging v0.0.0-20200819164719-22059654dac2/go.mod h1:80YyilHcgoqrnoIeeJKgcsOw6Y/0/bQzDO/XzNIrIdM= github.com/dfuse-io/logging v0.0.0-20200819170935-85f72399491a h1:L7CvV1OEGixk5pc5QpE2rIpR3m/2r7dEdUqtmxcpfkM= github.com/dfuse-io/logging v0.0.0-20200819170935-85f72399491a/go.mod h1:80YyilHcgoqrnoIeeJKgcsOw6Y/0/bQzDO/XzNIrIdM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= @@ -88,6 +86,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1 h1:/exdXoGamhu5ONeUJH0deniYLWYvQwW66yvlfiiKTu0= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -98,6 +98,7 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -146,6 +147,9 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 h1:EnfXoSqDfSNJv0VBNqY/88RNnhSGYkrHaO0mmFGbVsc= github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg= +github.com/mafredri/cdp v0.30.0 h1:Lvcwjajq6wB6Uk8dYeCLrF26LG85rUdpMxgrwdEvU0o= +github.com/mafredri/cdp v0.30.0/go.mod h1:71D84qPmWUvBWYj24Zp+U69mrUof4o8qL2X1fQJ/lHc= +github.com/mafredri/go-lint v0.0.0-20180911205320-920981dfc79e/go.mod h1:k/zdyxI3q6dup24o8xpYjJKTCf2F7rfxLp6w/efTiWs= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -238,6 +242,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/ybbus/jsonrpc v2.1.2+incompatible h1:V4mkE9qhbDQ92/MLMIhlhMSbz8jNXdagC3xBR5NDwaQ= github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= @@ -263,8 +268,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc h1:c0o/qxkaO2LF5t6fQrT4b5hzyggAkLLlCUjqfRxd8Q4= -golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -284,6 +289,8 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -301,6 +308,7 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -312,6 +320,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -359,7 +369,11 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200601175630-2caf76543d99 h1:deddXmhOJb/bvD/4M/j2AUMrhHeh6GkqykJSCWyTNVk= +golang.org/x/tools v0.0.0-20200601175630-2caf76543d99/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -417,9 +431,6 @@ gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v1.4.0 h1:BjtEgfuw8Qyd+jPvQz8CfoxiO/UjFEidWinwEXZiWv0= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= -gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/rpc/client.go b/rpc/client.go index e150832..e341403 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -1,47 +1,93 @@ package rpc import ( - "fmt" + "context" + "net/http" "github.com/dfuse-io/solana-go" + "github.com/ybbus/jsonrpc" ) type Client struct { - client jsonrpc.RPCClient - solanaEndpointAddr string + rpcURL string + rpcClient jsonrpc.RPCClient + headers http.Header + + Debug bool } -func NewClient(endpointAddr string) *Client { +func NewClient(rpcURL string) *Client { + rpcClient := jsonrpc.NewClient(rpcURL) return &Client{ - solanaEndpointAddr: endpointAddr, - client: jsonrpc.NewClient(endpointAddr), + rpcURL: rpcURL, + rpcClient: rpcClient, } } -func (c *Client) GetAccountInfo(publicKey solana.PublicKey) (*solana.GetAccountInfoResult, error) { - cfg := map[string]interface{}{ +func (c *Client) SetHeader(k, v string) { + if c.headers == nil { + c.headers = http.Header{} + } + c.headers.Set(k, v) +} + +func (c *Client) GetBalance(ctx context.Context, publicKey string, commitment solana.CommitmentType) (out *solana.GetBalanceResult, err error) { + params := []interface{}{publicKey} + if commitment != "" { + params = append(params, string(commitment)) + } + + err = c.rpcClient.CallFor(&out, "getBalance", params...) + return +} + +func (c *Client) GetRecentBlockhash(ctx context.Context, commitment solana.CommitmentType) (out *solana.GetRecentBlockhashResult, err error) { + var params []interface{} + if commitment != "" { + params = append(params, string(commitment)) + } + + err = c.rpcClient.CallFor(&out, "getRecentBlockhash", params...) + return +} + +func (c *Client) GetSlot(ctx context.Context, commitment solana.CommitmentType) (out solana.GetSlotResult, err error) { + var params []interface{} + if commitment != "" { + params = append(params, string(commitment)) + } + + err = c.rpcClient.CallFor(&out, "getSlot", params...) + return +} + +func (c *Client) GetConfirmedBlock(ctx context.Context, slot uint64, encoding string) (out *solana.GetConfirmedBlockResult, err error) { + if encoding == "" { + encoding = "json" + } + params := []interface{}{slot, encoding} + + err = c.rpcClient.CallFor(&out, "getConfirmedBlock", params...) + return +} + +func (c *Client) GetAccountInfo(ctx context.Context, publicKey solana.PublicKey) (out *solana.GetAccountInfoResult, err error) { + obj := map[string]interface{}{ "encoding": "base64", } + params := []interface{}{publicKey.String(), obj} - var reply solana.GetAccountInfoResult - err := c.client.CallFor(&reply, "getAccountInfo", publicKey.String(), cfg) - - if err != nil { - return nil, fmt.Errorf("getAccountInfo: %w", err) - } - return &reply, nil + err = c.rpcClient.CallFor(&out, "getAccountInfo", params...) + return } -func (c *Client) GetConfirmedBlock(slot uint64) error { - panic("need to full model here ...") - var reply map[string]interface{} - err := c.client.CallFor(&reply, "getConfirmedBlock", slot, "json") - - if err != nil { - return fmt.Errorf("calling getConfirmedBlock: %w", err) +func (c *Client) GetProgramAccounts(ctx context.Context, publicKey string, opts *solana.GetProgramAccountsOpts) (out *solana.GetProgramAccountsResult, err error) { + params := []interface{}{publicKey} + if opts != nil { + params = append(params, opts) } - fmt.Println("reply:", reply) - return nil + err = c.rpcClient.CallFor(&out, "getProgramAccounts", params...) + return } diff --git a/rpc/client_test.go b/rpc/client_test.go index e8ea5ee..cc752f3 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -1,6 +1,7 @@ package rpc import ( + "context" "encoding/json" "fmt" "testing" @@ -10,19 +11,12 @@ import ( "github.com/stretchr/testify/require" ) -func TestClient_GetConfirmedBlock(t *testing.T) { - - //rpcClient := NewRPCClient("api.mainnet-beta.solana.com:443") - c := NewClient("http://api.mainnet-beta.solana.com/rpc") - err := c.GetConfirmedBlock(46243868) - require.NoError(t, err) -} - func TestClient_GetAccountInfo(t *testing.T) { //rpcClient := NewRPCClient("api.mainnet-beta.solana.com:443") - c := NewClient("http://api.mainnet-beta.solana.com/rpc") - accInfo, err := c.GetAccountInfo(solana.MustPublicKeyFromBase58("7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932")) + c := NewClient("http://api.mainnet-beta.solana.com:80/rpc") + //c := NewClient("testnet.solana.com:8899") + accInfo, err := c.GetAccountInfo(context.Background(), solana.MustPublicKeyFromBase58("7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932")) require.NoError(t, err) d, err := json.MarshalIndent(accInfo, "", " ") require.NoError(t, err)