diff --git a/client.go b/client.go index 33d9b99..0462eb0 100644 --- a/client.go +++ b/client.go @@ -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) { diff --git a/client_test.go b/client_test.go index 3324d6a..256999c 100644 --- a/client_test.go +++ b/client_test.go @@ -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) +} diff --git a/types.go b/types.go index c834813..235c136 100644 --- a/types.go +++ b/types.go @@ -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.