Skip to content

Commit

Permalink
refactor: error handling should properly construct precheck errors vs…
Browse files Browse the repository at this point in the history
… receipt errors
  • Loading branch information
janaakhterov committed Apr 8, 2021
1 parent 3afb659 commit 9aef38a
Show file tree
Hide file tree
Showing 59 changed files with 354 additions and 190 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## v2.1.5-beta.2

### Fixed

* Executiong should retry on status `PLATFORM_TRANSACTION_NOT_CREATED`
* Error handling throughout the SDK
* A precheck error shoudl be returned when the exceptional status is in the header
* A receipt error should be returned when the exceptional status is in the receipt

## v2.1.5-beta.1

### Fixed
Expand Down
18 changes: 12 additions & 6 deletions account_balance_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ func (query *AccountBalanceQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
accountBalanceQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
accountBalanceQuery_getMethod,
accountBalanceQuery_mapResponseStatus,
accountBalanceQuery_mapStatusError,
query_mapResponse,
)

Expand All @@ -115,8 +115,14 @@ func (query *AccountBalanceQuery) GetCost(client *Client) (Hbar, error) {
return HbarFromTinybar(cost), nil
}

func accountBalanceQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetCryptogetAccountBalance().Header.NodeTransactionPrecheckCode)
func accountBalanceQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetCryptogetAccountBalance().Header.NodeTransactionPrecheckCode))
}

func accountBalanceQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetCryptogetAccountBalance().Header.NodeTransactionPrecheckCode),
}
}

func accountBalanceQuery_getMethod(_ request, channel *channel) method {
Expand All @@ -139,12 +145,12 @@ func (query *AccountBalanceQuery) Execute(client *Client) (AccountBalance, error
request{
query: &query.Query,
},
query_shouldRetry,
accountBalanceQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
accountBalanceQuery_getMethod,
accountBalanceQuery_mapResponseStatus,
accountBalanceQuery_mapStatusError,
query_mapResponse,
)

Expand Down
2 changes: 1 addition & 1 deletion account_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (transaction *AccountCreateTransaction) Execute(
transaction_advanceRequest,
transaction_getNodeAccountID,
accountCreateTransaction_getMethod,
transaction_mapResponseStatus,
transaction_mapStatusError,
transaction_mapResponse,
)

Expand Down
2 changes: 1 addition & 1 deletion account_delete_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (transaction *AccountDeleteTransaction) Execute(
transaction_advanceRequest,
transaction_getNodeAccountID,
accountDeleteTransaction_getMethod,
transaction_mapResponseStatus,
transaction_mapStatusError,
transaction_mapResponse,
)

Expand Down
18 changes: 12 additions & 6 deletions account_info_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ func NewAccountInfoQuery() *AccountInfoQuery {
}
}

func accountInfoQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetCryptoGetInfo().Header.NodeTransactionPrecheckCode)
func accountInfoQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetCryptoGetInfo().Header.NodeTransactionPrecheckCode))
}

func accountInfoQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetCryptoGetInfo().Header.NodeTransactionPrecheckCode),
}
}

func accountInfoQuery_getMethod(_ request, channel *channel) method {
Expand Down Expand Up @@ -58,12 +64,12 @@ func (query *AccountInfoQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
accountInfoQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
accountInfoQuery_getMethod,
accountInfoQuery_mapResponseStatus,
accountInfoQuery_mapStatusError,
query_mapResponse,
)

Expand Down Expand Up @@ -157,12 +163,12 @@ func (query *AccountInfoQuery) Execute(client *Client) (AccountInfo, error) {
request{
query: &query.Query,
},
query_shouldRetry,
accountInfoQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
accountInfoQuery_getMethod,
accountInfoQuery_mapResponseStatus,
accountInfoQuery_mapStatusError,
query_mapResponse,
)

Expand Down
18 changes: 12 additions & 6 deletions account_records_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func (query *AccountRecordsQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
accountRecordsQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
accountRecordsQuery_getMethod,
accountRecordsQuery_mapResponseStatus,
accountRecordsQuery_mapStatusError,
query_mapResponse,
)

Expand All @@ -80,8 +80,14 @@ func (query *AccountRecordsQuery) GetCost(client *Client) (Hbar, error) {
return HbarFromTinybar(cost), nil
}

func accountRecordsQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetCryptoGetAccountRecords().Header.NodeTransactionPrecheckCode)
func accountRecordsQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetCryptoGetAccountRecords().Header.NodeTransactionPrecheckCode))
}

func accountRecordsQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetCryptoGetAccountRecords().Header.NodeTransactionPrecheckCode),
}
}

func accountRecordsQuery_getMethod(_ request, channel *channel) method {
Expand Down Expand Up @@ -139,12 +145,12 @@ func (query *AccountRecordsQuery) Execute(client *Client) ([]TransactionRecord,
request{
query: &query.Query,
},
query_shouldRetry,
accountRecordsQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
accountRecordsQuery_getMethod,
accountRecordsQuery_mapResponseStatus,
accountRecordsQuery_mapStatusError,
query_mapResponse,
)

Expand Down
18 changes: 12 additions & 6 deletions account_stakers_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func (query *AccountStakersQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
accountStakersQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
accountStakersQuery_getMethod,
accountStakersQuery_mapResponseStatus,
accountStakersQuery_mapStatusError,
query_mapResponse,
)

Expand All @@ -80,8 +80,14 @@ func (query *AccountStakersQuery) GetCost(client *Client) (Hbar, error) {
return HbarFromTinybar(cost), nil
}

func accountStakersQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetCryptoGetProxyStakers().Header.NodeTransactionPrecheckCode)
func accountStakersQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetCryptoGetProxyStakers().Header.NodeTransactionPrecheckCode))
}

func accountStakersQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetCryptoGetProxyStakers().Header.NodeTransactionPrecheckCode),
}
}

func accountStakersQuery_getMethod(_ request, channel *channel) method {
Expand Down Expand Up @@ -137,12 +143,12 @@ func (query *AccountStakersQuery) Execute(client *Client) ([]Transfer, error) {
request{
query: &query.Query,
},
query_shouldRetry,
accountStakersQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
accountStakersQuery_getMethod,
accountStakersQuery_mapResponseStatus,
accountStakersQuery_mapStatusError,
query_mapResponse,
)

Expand Down
2 changes: 1 addition & 1 deletion account_update_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (transaction *AccountUpdateTransaction) Execute(
transaction_advanceRequest,
transaction_getNodeAccountID,
accountUpdateTransaction_getMethod,
transaction_mapResponseStatus,
transaction_mapStatusError,
transaction_mapResponse,
)

Expand Down
18 changes: 12 additions & 6 deletions contract_bytecode_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func (query *ContractBytecodeQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
contractBytecodeQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
contractBytecodeQuery_getMethod,
contractBytecodeQuery_mapResponseStatus,
contractBytecodeQuery_mapStatusError,
query_mapResponse,
)

Expand All @@ -72,8 +72,14 @@ func (query *ContractBytecodeQuery) GetCost(client *Client) (Hbar, error) {
return HbarFromTinybar(cost), nil
}

func contractBytecodeQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetContractGetBytecodeResponse().Header.NodeTransactionPrecheckCode)
func contractBytecodeQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetContractGetBytecodeResponse().Header.NodeTransactionPrecheckCode))
}

func contractBytecodeQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetContractGetBytecodeResponse().Header.NodeTransactionPrecheckCode),
}
}

func contractBytecodeQuery_getMethod(_ request, channel *channel) method {
Expand Down Expand Up @@ -129,12 +135,12 @@ func (query *ContractBytecodeQuery) Execute(client *Client) ([]byte, error) {
request{
query: &query.Query,
},
query_shouldRetry,
contractBytecodeQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
contractBytecodeQuery_getMethod,
contractBytecodeQuery_mapResponseStatus,
contractBytecodeQuery_mapStatusError,
query_mapResponse,
)

Expand Down
18 changes: 12 additions & 6 deletions contract_call_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (query *ContractCallQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
contractCallQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
contractCallQuery_getMethod,
contractCallQuery_mapResponseStatus,
contractCallQuery_mapStatusError,
query_mapResponse,
)

Expand All @@ -117,8 +117,14 @@ func (query *ContractCallQuery) GetCost(client *Client) (Hbar, error) {
return HbarFromTinybar(cost), nil
}

func contractCallQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetContractCallLocal().Header.NodeTransactionPrecheckCode)
func contractCallQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetContractCallLocal().Header.NodeTransactionPrecheckCode))
}

func contractCallQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetContractCallLocal().Header.NodeTransactionPrecheckCode),
}
}

func contractCallQuery_getMethod(_ request, channel *channel) method {
Expand Down Expand Up @@ -174,12 +180,12 @@ func (query *ContractCallQuery) Execute(client *Client) (ContractFunctionResult,
request{
query: &query.Query,
},
query_shouldRetry,
contractCallQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
contractCallQuery_getMethod,
contractCallQuery_mapResponseStatus,
contractCallQuery_mapStatusError,
query_mapResponse,
)

Expand Down
2 changes: 1 addition & 1 deletion contract_create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (transaction *ContractCreateTransaction) Execute(
transaction_advanceRequest,
transaction_getNodeAccountID,
contractCreateTransaction_getMethod,
transaction_mapResponseStatus,
transaction_mapStatusError,
transaction_mapResponse,
)

Expand Down
2 changes: 1 addition & 1 deletion contract_delete_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (transaction *ContractDeleteTransaction) Execute(
transaction_advanceRequest,
transaction_getNodeAccountID,
contractDeleteTransaction_getMethod,
transaction_mapResponseStatus,
transaction_mapStatusError,
transaction_mapResponse,
)

Expand Down
2 changes: 1 addition & 1 deletion contract_execute_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (transaction *ContractExecuteTransaction) Execute(
transaction_advanceRequest,
transaction_getNodeAccountID,
contractExecuteTransaction_getMethod,
transaction_mapResponseStatus,
transaction_mapStatusError,
transaction_mapResponse,
)

Expand Down
18 changes: 12 additions & 6 deletions contract_info_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func (query *ContractInfoQuery) GetCost(client *Client) (Hbar, error) {
request{
query: &query.Query,
},
query_shouldRetry,
contractInfoQuery_shouldRetry,
costQuery_makeRequest,
costQuery_advanceRequest,
costQuery_getNodeAccountID,
contractInfoQuery_getMethod,
contractInfoQuery_mapResponseStatus,
contractInfoQuery_mapStatusError,
query_mapResponse,
)

Expand All @@ -79,8 +79,14 @@ func (query *ContractInfoQuery) GetCost(client *Client) (Hbar, error) {
}
}

func contractInfoQuery_mapResponseStatus(_ request, response response) Status {
return Status(response.query.GetContractGetInfo().Header.NodeTransactionPrecheckCode)
func contractInfoQuery_shouldRetry(_ request, response response) executionState {
return query_shouldRetry(Status(response.query.GetContractGetInfo().Header.NodeTransactionPrecheckCode))
}

func contractInfoQuery_mapStatusError(_ request, response response) error {
return ErrHederaPreCheckStatus{
Status: Status(response.query.GetContractGetInfo().Header.NodeTransactionPrecheckCode),
}
}

func contractInfoQuery_getMethod(_ request, channel *channel) method {
Expand Down Expand Up @@ -136,12 +142,12 @@ func (query *ContractInfoQuery) Execute(client *Client) (ContractInfo, error) {
request{
query: &query.Query,
},
query_shouldRetry,
contractInfoQuery_shouldRetry,
query_makeRequest,
query_advanceRequest,
query_getNodeAccountID,
contractInfoQuery_getMethod,
contractInfoQuery_mapResponseStatus,
contractInfoQuery_mapStatusError,
query_mapResponse,
)

Expand Down
Loading

0 comments on commit 9aef38a

Please sign in to comment.