Repository: coinbase/rosetta-cli
Pull request #297 (2022-04-05 18:21:37)

BugFix: Add CoinSupported configuration
Fixes # .

### Motivation
This is a copy of PR: https://github.com/coinbase/rosetta-cli/pull/295/files by @aeharvlee. Since the author is in different timezone and a few asset issuers are waiting for the bug fix, I made this copy so we could merge and release by EOD.

### Solution
See PR for details.

### Open questions
N/A



Patch:
diff --git a/configuration/types.go b/configuration/types.go
index c0f53c3..1044143 100644
--- a/configuration/types.go
+++ b/configuration/types.go
@@ -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"`
 }
diff --git a/examples/configuration/default.json b/examples/configuration/default.json
index e119f90..11ee99f 100644
--- a/examples/configuration/default.json
+++ b/examples/configuration/default.json
@@ -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,


Test patch:
diff --git a/pkg/tester/construction.go b/pkg/tester/construction.go
index 53ff7e8..ac763bb 100644
--- a/pkg/tester/construction.go
+++ b/pkg/tester/construction.go
@@ -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)
@@ -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)
+		}
 	}
 
 	// --------------------------------------------------------------------------