Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Revert "feat(BUX-236): transaction submitting in RawTx format for bac…
Browse files Browse the repository at this point in the history
…kwards compatibility (#41)" (#45)

This reverts commit 4ecd8d1.
  • Loading branch information
kuba-4chain authored Oct 12, 2023
1 parent 6e3ff91 commit 7939ff8
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 368 deletions.
92 changes: 30 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Having your client created, you can use the method `SubmitTx` to submit a single
```go
// ...
tx := broadcast.Transaction{
Hex: "xyz",
RawTx: "xyz",
}

result, err := client.SubmitTransaction(context.Background(), tx)
Expand All @@ -167,46 +167,14 @@ Having your client created, you can use the method `SubmitTx` to submit a single

You need to pass the [transaction](#transaction) as a parameter to the method `SubmitTransaction`.

You may add options to this method:

##### WithCallback

```go
result, err := client.SubmitTransaction(context.Background(), tx, broadcast.WithCallback(callBackUrl, callbackToken))
```
Setting `CallbackURL` and `CallBackToken` will add the headers `X-CallbackUrl` and `X-CallbackToken` to the request.
It will allow you to get the callback from the node when the transaction is mined, and receive the transaction details and status.

##### WithMerkleProof

```go
result, err := client.SubmitTransaction(context.Background(), tx, broadcast.WithMerkleProof())
```
Setting `MerkleProof` to true will add the header `X-MerkleProof` to the request.
Setting tx.MerkleProof to true will add the header `X-MerkleProof` to the request.
MerkleProof while broadcasting will handle the merkle proof capability of the node.

##### WithWaitForstatus

```go
result, err := client.SubmitTransaction(context.Background(), tx, broadcast.WithWaitForstatus(broadcast.AnnouncedToNetwork))
```
Setting `WaitForStatus` will add the header `X-WaitForStatus` to the request.
It will allow you to return the result only when the transaction reaches the status you set.

##### WithBeefFormat

```go
result, err := client.SubmitTransaction(context.Background(), tx, broadcast.WithBeefFormat())
```
Setting `BeefFormat` will accept your transaction in BEEF format and decode it for a proper format acceptable by Arc.

##### WithRawFormat (**DEPRECATED!**)
Setting tx.CallBackURL and tx.CallBackToken will add the headers `X-CallbackUrl` and `X-CallbackToken` to the request.
It will allow you to get the callback from the node when the transaction is mined, and receive the transaction details and status.

```go
result, err := client.SubmitTransaction(context.Background(), tx, broadcast.WithRawFormat())
```
Setting `RawFormat` will accept your transaction in RawTx format and encode it for a proper format acceptable by Arc.
This option will become deprecated soon.
Setting tx.WaitForStatus will add the header `X-WaitForStatus` to the request.
It will allow you to wait for the transaction to be mined and return the result only when the transaction reaches the status you set.

### SubmitBatchTx Method

Expand All @@ -215,11 +183,11 @@ Having your client created, you can use the method `SubmitBatchTx` to submit a b
```go
// ...
txs := []*broadcast.Transaction{
{Hex: "xyz1"},
{Hex: "xyz2"},
{Hex: "xyz3"},
{Hex: "xyz4"},
{Hex: "xyz5"},
{RawTx: "xyz1"},
{RawTx: "xyz2"},
{RawTx: "xyz3"},
{RawTx: "xyz4"},
{RawTx: "xyz5"},
}

result, err := client.SubmitBatchTransaction(context.Background(), txs)
Expand All @@ -236,11 +204,11 @@ The method works the same as the `SubmitTx` method, but it is sending a batch of

```go
type QueryTxResponse struct {
BlockHash string `json:"blockHash,omitempty"`
BlockHeight int64 `json:"blockHeight,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
TxID string `json:"txid,omitempty"`
TxStatus TxStatus `json:"txStatus,omitempty"`
BlockHash string `json:"blockHash,omitempty"`
BlockHeight int64 `json:"blockHeight,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
TxID string `json:"txid,omitempty"`
TxStatus TxStatus `json:"txStatus,omitempty"`
}
```

Expand Down Expand Up @@ -294,27 +262,27 @@ type FeeQuote struct {

```go
type SubmitTxResponse struct {
BlockHash string `json:"blockHash,omitempty"`
BlockHeight int64 `json:"blockHeight,omitempty"`
ExtraInfo string `json:"extraInfo,omitempty"`
Status int `json:"status,omitempty"`
Title string `json:"title,omitempty"`
TxStatus TxStatus `json:"txStatus,omitempty"`
BlockHash string `json:"blockHash,omitempty"`
BlockHeight int64 `json:"blockHeight,omitempty"`
ExtraInfo string `json:"extraInfo,omitempty"`
Status int `json:"status,omitempty"`
Title string `json:"title,omitempty"`
TxStatus TxStatus `json:"txStatus,omitempty"`
}
```

#### Transaction

```go
type Transaction struct {
CallBackEncryption string `json:"callBackEncryption,omitempty"`
CallBackToken string `json:"callBackToken,omitempty"`
CallBackURL string `json:"callBackUrl,omitempty"`
DsCheck bool `json:"dsCheck,omitempty"`
MerkleFormat string `json:"merkleFormat,omitempty"`
MerkleProof bool `json:"merkleProof,omitempty"`
Hex string `json:"hex"`
WaitForStatus TxStatus `json:"waitForStatus,omitempty"`
CallBackEncryption string `json:"callBackEncryption,omitempty"`
CallBackToken string `json:"callBackToken,omitempty"`
CallBackURL string `json:"callBackUrl,omitempty"`
DsCheck bool `json:"dsCheck,omitempty"`
MerkleFormat string `json:"merkleFormat,omitempty"`
MerkleProof bool `json:"merkleProof,omitempty"`
RawTx string `json:"rawtx"`
WaitForStatus TxStatus `json:"waitForStatus,omitempty"`
}
```

Expand Down
12 changes: 6 additions & 6 deletions broadcast/broadcast-client-mock/mock_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMockClientSuccess(t *testing.T) {
Build()

// when
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{Hex: "test-rawtx"})
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{RawTx: "test-rawtx"})

// then
assert.NoError(t, err)
Expand All @@ -98,7 +98,7 @@ func TestMockClientSuccess(t *testing.T) {
}

// when
result, err := broadcaster.SubmitBatchTransactions(context.Background(), []*broadcast.Transaction{{Hex: "test-rawtx"}, {Hex: "test2-rawtx"}})
result, err := broadcaster.SubmitBatchTransactions(context.Background(), []*broadcast.Transaction{{RawTx: "test-rawtx"}, {RawTx: "test2-rawtx"}})

// then
assert.NoError(t, err)
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestMockClientFailure(t *testing.T) {
Build()

// when
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{Hex: "test-rawtx"})
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{RawTx: "test-rawtx"})

// then
assert.Error(t, err)
Expand All @@ -175,7 +175,7 @@ func TestMockClientFailure(t *testing.T) {
Build()

// when
result, err := broadcaster.SubmitBatchTransactions(context.Background(), []*broadcast.Transaction{{Hex: "test-rawtx"}, {Hex: "test2-rawtx"}})
result, err := broadcaster.SubmitBatchTransactions(context.Background(), []*broadcast.Transaction{{RawTx: "test-rawtx"}, {RawTx: "test2-rawtx"}})

// then
assert.Error(t, err)
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestMockClientTimeout(t *testing.T) {
startTime := time.Now()

// when
result, err := broadcaster.SubmitTransaction(ctx, &broadcast.Transaction{Hex: "test-rawtx"})
result, err := broadcaster.SubmitTransaction(ctx, &broadcast.Transaction{RawTx: "test-rawtx"})

// then
assert.NoError(t, err)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestMockClientTimeout(t *testing.T) {
}

// when
result, err := broadcaster.SubmitBatchTransactions(ctx, []*broadcast.Transaction{{Hex: "test-rawtx"}, {Hex: "test2-rawtx"}})
result, err := broadcaster.SubmitBatchTransactions(ctx, []*broadcast.Transaction{{RawTx: "test-rawtx"}, {RawTx: "test2-rawtx"}})

// then
assert.NoError(t, err)
Expand Down
24 changes: 12 additions & 12 deletions broadcast/internal/acceptance_tests/arc_submit_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestSubmitTransaction(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse2, nil).Times(0)

// when
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{Hex: "transaction-data"})
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{RawTx: "transaction-data"})

// then
httpClientMock.AssertExpectations(t)
Expand All @@ -74,7 +74,7 @@ func TestSubmitTransaction(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse, errors.New("http error")).Once()

// when
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{Hex: "transaction-data"})
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{RawTx: "transaction-data"})

// then
httpClientMock.AssertExpectations(t)
Expand All @@ -98,7 +98,7 @@ func TestSubmitTransaction(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse, errors.New("http error")).Once()

// when
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{Hex: "transaction-data"})
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{RawTx: "transaction-data"})

// then
httpClientMock.AssertExpectations(t)
Expand All @@ -122,7 +122,7 @@ func TestSubmitTransaction(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse2, nil).Once()

// when
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{Hex: "transaction-data"})
result, err := broadcaster.SubmitTransaction(context.Background(), &broadcast.Transaction{RawTx: "transaction-data"})

// then
httpClientMock.AssertExpectations(t)
Expand All @@ -146,8 +146,8 @@ func TestSubmitBatchTransactions(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse2, nil).Times(0)

batch := []*broadcast.Transaction{
{Hex: "transaction-0-data"},
{Hex: "transaction-1-data"},
{RawTx: "transaction-0-data"},
{RawTx: "transaction-1-data"},
}

// when
Expand All @@ -174,8 +174,8 @@ func TestSubmitBatchTransactions(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse2, nil).Once()

batch := []*broadcast.Transaction{
{Hex: "transaction-0-data"},
{Hex: "transaction-1-data"},
{RawTx: "transaction-0-data"},
{RawTx: "transaction-1-data"},
}

// when
Expand All @@ -198,8 +198,8 @@ func TestSubmitBatchTransactions(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse, errors.New("http error")).Once()

batch := []*broadcast.Transaction{
{Hex: "transaction-0-data"},
{Hex: "transaction-1-data"},
{RawTx: "transaction-0-data"},
{RawTx: "transaction-1-data"},
}

// when
Expand All @@ -223,8 +223,8 @@ func TestSubmitBatchTransactions(t *testing.T) {
httpClientMock.On("DoRequest", mock.Anything, mock.Anything).Return(httpResponse, errors.New("http error")).Once()

batch := []*broadcast.Transaction{
{Hex: "transaction-0-data"},
{Hex: "transaction-1-data"},
{RawTx: "transaction-0-data"},
{RawTx: "transaction-1-data"},
}

// when
Expand Down
Loading

0 comments on commit 7939ff8

Please sign in to comment.