Skip to content

Commit

Permalink
ROSE-239: BugFix: Add CoinSupported configuration (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiatcb committed Apr 5, 2022
1 parent 3b3f574 commit 3497461
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
6 changes: 6 additions & 0 deletions configuration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ type Configuration struct {
// if the data or construction check fails
ErrorStackTraceDisabled bool `json:"error_stack_trace_disabled"`

// CoinSupported indicates whether your implementation support coins or not.
// If your implementation is based on account-based blockchain (e.g. Ethereum),
// this value must be false. If your implementation is UTXO-based blockchain (e.g. Bitcoin),
// then this value must be true.
CoinSupported bool `json:"coin_supported"`

Construction *ConstructionConfiguration `json:"construction"`
Data *DataConfiguration `json:"data"`
}
1 change: 1 addition & 0 deletions examples/configuration/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"compression_disabled": false,
"memory_limit_disabled": false,
"error_stack_trace_disabled": false,
"coin_supported": false,
"construction": null,
"data": {
"active_reconciliation_concurrency": 16,
Expand Down
45 changes: 25 additions & 20 deletions pkg/tester/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,18 @@ func InitializeConstruction(
Currency: prefundedAcc.Currency,
}

acctCoinsReq := &utils.AccountCoinsRequest{
Account: prefundedAcc.AccountIdentifier,
Network: network,
Currencies: []*types.Currency{prefundedAcc.Currency},
IncludeMempool: false,
}

accountBalanceRequests = append(accountBalanceRequests, accountBalance)
acctCoinsReqs = append(acctCoinsReqs, acctCoinsReq)

if config.CoinSupported {
acctCoinsReq := &utils.AccountCoinsRequest{
Account: prefundedAcc.AccountIdentifier,
Network: network,
Currencies: []*types.Currency{prefundedAcc.Currency},
IncludeMempool: false,
}

acctCoinsReqs = append(acctCoinsReqs, acctCoinsReq)
}
}

accBalances, err := utils.GetAccountBalances(ctx, onlineFetcher, accountBalanceRequests)
Expand All @@ -238,20 +241,22 @@ func InitializeConstruction(
// ------------ Get account coins and add them in coins storage ------------
// -------------------------------------------------------------------------

acctCoins, errAccCoins := utils.GetAccountCoins(ctx, onlineFetcher, acctCoinsReqs)
if errAccCoins != nil {
return nil, fmt.Errorf("%w: unable to get account coins", errAccCoins)
}
if config.CoinSupported {
acctCoins, errAccCoins := utils.GetAccountCoins(ctx, onlineFetcher, acctCoinsReqs)
if errAccCoins != nil {
return nil, fmt.Errorf("%w: unable to get account coins", errAccCoins)
}

// Extract accounts from account coins requests
var accts []*types.AccountIdentifier
for _, req := range acctCoinsReqs {
accts = append(accts, req.Account)
}
// Extract accounts from account coins requests
var accts []*types.AccountIdentifier
for _, req := range acctCoinsReqs {
accts = append(accts, req.Account)
}

err = coinStorage.SetCoinsImported(ctx, accts, acctCoins)
if err != nil {
return nil, fmt.Errorf("%w: unable to set coin balances", err)
err = coinStorage.SetCoinsImported(ctx, accts, acctCoins)
if err != nil {
return nil, fmt.Errorf("%w: unable to set coin balances", err)
}
}

// --------------------------------------------------------------------------
Expand Down

0 comments on commit 3497461

Please sign in to comment.