Skip to content

Commit

Permalink
CORE-207: BRFileService error handling (part #1, on fileServiceSave).…
Browse files Browse the repository at this point in the history
… Update BREthereumEWM and BRWalletManager for fileService error handling.
  • Loading branch information
Ed Gamble committed Jan 25, 2019
1 parent 03d0439 commit efe9084
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 98 deletions.
63 changes: 37 additions & 26 deletions BRWalletManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,25 @@ bwmFileServiceErrorHandler (BRFileServiceContext context,
///
/// MARK: Wallet Manager
///
static BRWalletManager
bwmCreateErrorHandler (BRWalletManager bwm, int fileService, const char* reason) {
if (NULL != bwm) free (bwm);
if (fileService)
_peer_log ("bread: on ewmCreate: FileService Error: %s", reason);
else
_peer_log ("bread: on ewmCreate: Error: %s", reason);

return NULL;
}

extern BRWalletManager
BRWalletManagerNew (BRWalletManagerClient client,
BRMasterPubKey mpk,
const BRChainParams *params,
uint32_t earliestKeyTime,
const char *baseStoragePath) {
BRWalletManager manager = malloc (sizeof (struct BRWalletManagerStruct));
if (NULL == manager) return NULL;
if (NULL == manager) return bwmCreateErrorHandler (NULL, 0, "allocate");

// manager->walletForkId = fork;
manager->client = client;
Expand All @@ -379,37 +390,37 @@ BRWalletManagerNew (BRWalletManagerClient client,
manager->fileService = fileServiceCreate (baseStoragePath, networkName, currencyName,
manager,
bwmFileServiceErrorHandler);
if (NULL == manager->fileService) { free (manager); return NULL; }
if (NULL == manager->fileService) return bwmCreateErrorHandler (manager, 1, "create");

/// Transaction
fileServiceDefineType (manager->fileService, fileServiceTypeTransactions,
(BRFileServiceContext) manager,
WALLET_MANAGER_TRANSACTION_VERSION_1,
fileServiceTypeTransactionV1Identifier,
fileServiceTypeTransactionV1Reader,
fileServiceTypeTransactionV1Writer);
fileServiceDefineCurrentVersion (manager->fileService, fileServiceTypeTransactions,
WALLET_MANAGER_TRANSACTION_VERSION_1);
if (1 != fileServiceDefineType (manager->fileService, fileServiceTypeTransactions, WALLET_MANAGER_TRANSACTION_VERSION_1,
(BRFileServiceContext) manager,
fileServiceTypeTransactionV1Identifier,
fileServiceTypeTransactionV1Reader,
fileServiceTypeTransactionV1Writer) ||
1 != fileServiceDefineCurrentVersion (manager->fileService, fileServiceTypeTransactions,
WALLET_MANAGER_TRANSACTION_VERSION_1))
return bwmCreateErrorHandler (manager, 1, fileServiceTypeTransactions);

/// Block
fileServiceDefineType (manager->fileService, fileServiceTypeBlocks,
(BRFileServiceContext) manager,
WALLET_MANAGER_BLOCK_VERSION_1,
fileServiceTypeBlockV1Identifier,
fileServiceTypeBlockV1Reader,
fileServiceTypeBlockV1Writer);
fileServiceDefineCurrentVersion (manager->fileService, fileServiceTypeBlocks,
WALLET_MANAGER_BLOCK_VERSION_1);
if (1 != fileServiceDefineType (manager->fileService, fileServiceTypeBlocks, WALLET_MANAGER_BLOCK_VERSION_1,
(BRFileServiceContext) manager,
fileServiceTypeBlockV1Identifier,
fileServiceTypeBlockV1Reader,
fileServiceTypeBlockV1Writer) ||
1 != fileServiceDefineCurrentVersion (manager->fileService, fileServiceTypeBlocks,
WALLET_MANAGER_BLOCK_VERSION_1))
return bwmCreateErrorHandler (manager, 1, fileServiceTypeBlocks);

/// Peer
fileServiceDefineType (manager->fileService, fileServiceTypePeers,
(BRFileServiceContext) manager,
WALLET_MANAGER_PEER_VERSION_1,
fileServiceTypePeerV1Identifier,
fileServiceTypePeerV1Reader,
fileServiceTypePeerV1Writer);
fileServiceDefineCurrentVersion (manager->fileService, fileServiceTypePeers,
WALLET_MANAGER_PEER_VERSION_1);
if (1 != fileServiceDefineType (manager->fileService, fileServiceTypePeers, WALLET_MANAGER_PEER_VERSION_1,
(BRFileServiceContext) manager,
fileServiceTypePeerV1Identifier,
fileServiceTypePeerV1Reader,
fileServiceTypePeerV1Writer) ||
1 != fileServiceDefineCurrentVersion (manager->fileService, fileServiceTypePeers,
WALLET_MANAGER_PEER_VERSION_1))
return bwmCreateErrorHandler (manager, 1, fileServiceTypePeers);

/// Load transactions for the wallet manager.
BRArrayOf(BRTransaction*) transactions = initialTransactionsLoad(manager);
Expand Down
77 changes: 44 additions & 33 deletions ethereum/ewm/BREthereumEWM.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ ewmFileServiceErrorHandler (BRFileServiceContext context,
///
/// MARK: Ethereum Wallet Manager
///
static BREthereumEWM
ewmCreateErrorHandler (BREthereumEWM ewm, int fileService, const char* reason) {
if (NULL != ewm) free (ewm);
if (fileService)
eth_log ("EWM", "on ewmCreate: FileService Error: %s", reason);
else
eth_log ("EWM", "on ewmCreate: Error: %s", reason);

return NULL;
}

extern BREthereumEWM
ewmCreate (BREthereumNetwork network,
Expand Down Expand Up @@ -379,47 +389,48 @@ ewmCreate (BREthereumNetwork network,
ewm->fs = fileServiceCreate (storagePath, networkGetName(network), "eth",
ewm,
ewmFileServiceErrorHandler);
if (NULL == ewm->fs) { free (ewm); return NULL; }
if (NULL == ewm->fs) return ewmCreateErrorHandler(ewm, 1, "create");

/// Transaction
fileServiceDefineType (ewm->fs, fileServiceTypeTransactions,
(BRFileServiceContext) ewm,
EWM_TRANSACTION_VERSION_1,
fileServiceTypeTransactionV1Identifier,
fileServiceTypeTransactionV1Reader,
fileServiceTypeTransactionV1Writer);
fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeTransactions,
EWM_TRANSACTION_VERSION_1);
if (1 != fileServiceDefineType (ewm->fs, fileServiceTypeTransactions, EWM_TRANSACTION_VERSION_1,
(BRFileServiceContext) ewm,
fileServiceTypeTransactionV1Identifier,
fileServiceTypeTransactionV1Reader,
fileServiceTypeTransactionV1Writer) ||
1 != fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeTransactions,
EWM_TRANSACTION_VERSION_1))
return ewmCreateErrorHandler(ewm, 1, fileServiceTypeTransactions);

/// Log
fileServiceDefineType (ewm->fs, fileServiceTypeLogs,
(BRFileServiceContext) ewm,
EWM_LOG_VERSION_1,
fileServiceTypeLogV1Identifier,
fileServiceTypeLogV1Reader,
fileServiceTypeLogV1Writer);
fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeLogs,
EWM_LOG_VERSION_1);
if (1 != fileServiceDefineType (ewm->fs, fileServiceTypeLogs, EWM_LOG_VERSION_1,
(BRFileServiceContext) ewm,
fileServiceTypeLogV1Identifier,
fileServiceTypeLogV1Reader,
fileServiceTypeLogV1Writer) ||
1 != fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeLogs,
EWM_LOG_VERSION_1))
return ewmCreateErrorHandler(ewm, 1, fileServiceTypeLogs);

/// Peer
fileServiceDefineType (ewm->fs, fileServiceTypeNodes,
(BRFileServiceContext) ewm,
EWM_NODE_VERSION_1,
fileServiceTypeNodeV1Identifier,
fileServiceTypeNodeV1Reader,
fileServiceTypeNodeV1Writer);
fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeNodes,
EWM_NODE_VERSION_1);
if (1 != fileServiceDefineType (ewm->fs, fileServiceTypeNodes, EWM_NODE_VERSION_1,
(BRFileServiceContext) ewm,
fileServiceTypeNodeV1Identifier,
fileServiceTypeNodeV1Reader,
fileServiceTypeNodeV1Writer) ||
1 != fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeNodes,
EWM_NODE_VERSION_1))
return ewmCreateErrorHandler(ewm, 1, fileServiceTypeNodes);


/// Block
fileServiceDefineType (ewm->fs, fileServiceTypeBlocks,
(BRFileServiceContext) ewm,
EWM_BLOCK_VERSION_1,
fileServiceTypeBlockV1Identifier,
fileServiceTypeBlockV1Reader,
fileServiceTypeBlockV1Writer);
fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeBlocks,
EWM_BLOCK_VERSION_1);
if (1 != fileServiceDefineType (ewm->fs, fileServiceTypeBlocks, EWM_BLOCK_VERSION_1,
(BRFileServiceContext) ewm,
fileServiceTypeBlockV1Identifier,
fileServiceTypeBlockV1Reader,
fileServiceTypeBlockV1Writer) ||
1 != fileServiceDefineCurrentVersion (ewm->fs, fileServiceTypeBlocks,
EWM_BLOCK_VERSION_1))
return ewmCreateErrorHandler(ewm, 1, fileServiceTypeBlocks);

// Load all the persistent entities
BRSetOf(BREthereumTransaction) transactions = initialTransactionsLoad(ewm);
Expand Down
Loading

0 comments on commit efe9084

Please sign in to comment.