Skip to content

Commit

Permalink
Implement SubmitTx method
Browse files Browse the repository at this point in the history
Signed-off-by: Regis-Caelum <[email protected]>
  • Loading branch information
Regis-Caelum committed May 31, 2022
1 parent 76047a6 commit 8faaf0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
22 changes: 19 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,25 @@ func (c *Client) Balance(ctx context.Context) error {
return nil
}

func (c *Client) SubmitTx(ctx context.Context, tx []byte) /* TxResponse */ error {
_ = submitTxEndpoint
return errors.New("method SubmitTx not implemented")
func (c *Client) SubmitTx(ctx context.Context, tx []byte) (*TxResponse, error) {
req := SubmitTxRequest{
Tx: string(tx),
}
var res TxResponse
var rpcErr string
_, err := c.c.R().
SetContext(ctx).
SetBody(req).
SetResult(&res).
SetError(&rpcErr).
Post(submitTxEndpoint)
if err != nil {
return nil, err
}
if rpcErr != "" {
return nil, errors.New(rpcErr)
}
return &res, nil
}

func (c *Client) SubmitPFD(ctx context.Context, namespaceID [8]byte, data []byte, gasLimit uint64) (*TxResponse, error) {
Expand Down
10 changes: 10 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ func TestBalance(t *testing.T) {
_, err := NewClient("http://localhost:26658", WithTimeout(5*time.Second))
assert.NoError(t, err)
}

func TestSubmitTx(t *testing.T) {
client, err := NewClient("http://localhost:26658", WithTimeout(30*time.Second))
assert.NoError(t, err)
assert.NotNil(t, client)

txRes, err := client.SubmitTx(context.TODO(), []byte("0A83080AFE070A1A2F7061796D656E742E4D736757697265506179466F724461746112DF070A2C63656C65733133753364376D6E757930327070397A6B337A707165706A66746A66376476727A6E6B6C333271120802020202020202021880042280040202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202326608101220B0429A0DB28AE163D9C1A300B320B19CEF93EC90AE87B4BA7ECF76C0703A9F891A408FA20C490F620B6A02E7FF5FA4139B997969BADE13A5E4F1A35086670FDC71550447A4759D57C844E836947F4BB73039D0E836511F3B1B8D8F1D317248DAF707326608201220B0429A0DB28AE163D9C1A300B320B19CEF93EC90AE87B4BA7ECF76C0703A9F891A408FA20C490F620B6A02E7FF5FA4139B997969BADE13A5E4F1A35086670FDC71550447A4759D57C844E836947F4BB73039D0E836511F3B1B8D8F1D317248DAF707326608401220B0429A0DB28AE163D9C1A300B320B19CEF93EC90AE87B4BA7ECF76C0703A9F891A408FA20C490F620B6A02E7FF5FA4139B997969BADE13A5E4F1A35086670FDC71550447A4759D57C844E836947F4BB73039D0E836511F3B1B8D8F1D317248DAF70732670880011220B0429A0DB28AE163D9C1A300B320B19CEF93EC90AE87B4BA7ECF76C0703A9F891A408FA20C490F620B6A02E7FF5FA4139B997969BADE13A5E4F1A35086670FDC71550447A4759D57C844E836947F4BB73039D0E836511F3B1B8D8F1D317248DAF707186312550A4E0A460A1F2F636F736D6F732E63727970746F2E736563703235366B312E5075624B657912230A210318F208E403FE5881227DD423254DA2BD4C11BAD740820B23DA352EF0E7581E6412040A020801120310904E1A405311CD1C8888C562CAA95BF4FBBD6646604D59D66FDD8E291A1C1B2C5286727464E0B3DD9E7DF38F681E0D7A2A154AED45810B6A59D351DE105D11D9383E0D44"))
assert.NoError(t, err)
assert.NotNil(t, txRes)
}
4 changes: 4 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type balanceResponse struct {
Amount string `json:"amount"`
}

type SubmitTxRequest struct {
Tx string `json:"tx"`
}

// Types below are copied from celestia-node (or cosmos-sdk dependency of celestia node, to be precise)
// They are needed for proper deserialization.
// It's probably far from the best approach to those types, but it's simple and works.
Expand Down

0 comments on commit 8faaf0a

Please sign in to comment.