Skip to content

Commit

Permalink
feat: allow configuring arc status to wait for when broadcasting tran…
Browse files Browse the repository at this point in the history
…sactions
  • Loading branch information
arkadiuszos4chain committed Jan 30, 2025
1 parent 3893827 commit d59722a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ type DatastoreConfig struct {

// ARCConfig consists of blockchain nodes (Arc) configuration
type ARCConfig struct {
Callback *CallbackConfig `json:"callback" mapstructure:"callback"`
DeploymentID string `json:"deployment_id" mapstructure:"deployment_id"`
Token string `json:"token" mapstructure:"token"`
URL string `json:"url" mapstructure:"url"`
Callback *CallbackConfig `json:"callback" mapstructure:"callback"`
DeploymentID string `json:"deployment_id" mapstructure:"deployment_id"`
Token string `json:"token" mapstructure:"token"`
URL string `json:"url" mapstructure:"url"`
WaitForStatus string `json:"wait_for_status" mapstructure:"wait_for_status"`
}

// FeeUnitConfig reflects the utils.FeeUnit struct with proper annotations for json and mapstructure
Expand Down
1 change: 1 addition & 0 deletions config/config_to_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (c *AppConfig) addARCOpts(options []engine.ClientOps) ([]engine.ClientOps,
URL: c.ARC.URL,
Token: c.ARC.Token,
DeploymentID: c.ARC.DeploymentID,
WaitFor: c.ARC.WaitForStatus,
}

if c.ARC.Callback.Enabled {
Expand Down
11 changes: 9 additions & 2 deletions engine/chain/internal/arc/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"

sdk "github.com/bitcoin-sv/go-sdk/transaction"
"github.com/bitcoin-sv/spv-wallet/engine/chain/errors"
"github.com/bitcoin-sv/spv-wallet/engine/chain/models"
chainerrors "github.com/bitcoin-sv/spv-wallet/engine/chain/errors"
chainmodels "github.com/bitcoin-sv/spv-wallet/engine/chain/models"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/go-resty/resty/v2"
)
Expand All @@ -29,6 +29,7 @@ func (s *Service) Broadcast(ctx context.Context, tx *sdk.Transaction) (*chainmod
SetError(arcErr)

s.setCallbackHeaders(req)
s.setWaitForHeader(req)

txHex, err := s.prepareTxHex(ctx, tx)
if err != nil {
Expand Down Expand Up @@ -92,3 +93,9 @@ func (s *Service) setCallbackHeaders(req *resty.Request) {
}
}
}

func (s *Service) setWaitForHeader(req *resty.Request) {
if s.arcCfg.WaitFor != "" {
req.SetHeader("X-WaitFor", s.arcCfg.WaitFor)
}
}
1 change: 1 addition & 0 deletions engine/chain/models/arc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ARCConfig struct {
URL string
Token string
DeploymentID string
WaitFor string
Callback *ARCCallbackConfig
UseJunglebus bool
TxsGetter TransactionsGetter
Expand Down

0 comments on commit d59722a

Please sign in to comment.