From 4b388cf54f36333ebc00fd6c12af08371e23b8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Wed, 18 Oct 2023 14:14:09 +0200 Subject: [PATCH 1/3] Expand blockIssuance api with query param: slotIndex --- nodeclient/http_api_client.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nodeclient/http_api_client.go b/nodeclient/http_api_client.go index 0a5b52df7..c4a0b50c3 100644 --- a/nodeclient/http_api_client.go +++ b/nodeclient/http_api_client.go @@ -373,10 +373,15 @@ func (client *Client) Info(ctx context.Context) (*apimodels.InfoResponse, error) } // BlockIssuance gets the info to issue a block. -func (client *Client) BlockIssuance(ctx context.Context) (*apimodels.IssuanceBlockHeaderResponse, error) { +func (client *Client) BlockIssuance(ctx context.Context, optSlotIndex ...iotago.SlotIndex) (*apimodels.IssuanceBlockHeaderResponse, error) { + query := RouteBlockIssuance + if len(optSlotIndex) > 0 { + query += fmt.Sprintf("?slotIndex=%d", optSlotIndex[0]) + } res := new(apimodels.IssuanceBlockHeaderResponse) + //nolint:bodyclose - if _, err := client.Do(ctx, http.MethodGet, RouteBlockIssuance, nil, res); err != nil { + if _, err := client.Do(ctx, http.MethodGet, query, nil, res); err != nil { return nil, err } From 14794e5ed0b838700a76b2bf9256c8f0ebb66c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Wed, 18 Oct 2023 14:30:11 +0200 Subject: [PATCH 2/3] Update comment --- nodeclient/http_api_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodeclient/http_api_client.go b/nodeclient/http_api_client.go index c4a0b50c3..0a13558d0 100644 --- a/nodeclient/http_api_client.go +++ b/nodeclient/http_api_client.go @@ -545,7 +545,7 @@ func (client *Client) TransactionIncludedBlock(ctx context.Context, txID iotago. return block, nil } -// BlockMetadataByBlockID gets the metadata of a block by its ID from the node. +// TransactionIncludedBlockMetadata gets the metadata of a block by its ID from the node. func (client *Client) TransactionIncludedBlockMetadata(ctx context.Context, txID iotago.TransactionID) (*apimodels.BlockMetadataResponse, error) { query := fmt.Sprintf(RouteTransactionsIncludedBlockMetadata, hexutil.EncodeHex(txID[:])) From 2efd49449601f4d66af5820bbed72ad6f33ae4d7 Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Thu, 19 Oct 2023 15:47:30 +0800 Subject: [PATCH 3/3] Add block failure codes --- error.go | 21 +++++++++++++++++++++ nodeclient/apimodels/core.go | 23 +++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/error.go b/error.go index 03961a8ae..7a9f93086 100644 --- a/error.go +++ b/error.go @@ -6,6 +6,27 @@ import ( // Errors used by failure codes +// Errors used for block failures. +var ( + // ErrIssuerAccountNotFound gets returned when the issuer account could not be found. + ErrIssuerAccountNotFound = ierrors.New("could not retrieve account information for block issuer") + // ErrBurnedInsufficientMana gets returned when the issuer account burned insufficient Mana for a block. + ErrBurnedInsufficientMana = ierrors.New("block issuer account burned insufficient Mana") + // ErrBlockVersionInvalid gets returned when the block version is invalid to retrieve API. + ErrBlockVersionInvalid = ierrors.New("could not retrieve API for block version") + // ErrRMCNotFound gets returned when the RMC could not be found from the slot commitment. + ErrRMCNotFound = ierrors.New("could not retrieve RMC for slot commitment") + // ErrFailedToCalculateManaCost gets returned when the Mana cost could not be calculated. + ErrFailedToCalculateManaCost = ierrors.New("could not calculate Mana cost for block") + // ErrNegativeBIC gets returned when the BIC of the issuer account is negative. + ErrNegativeBIC = ierrors.New("negative BIC") + // ErrAccountExpired gets returned when the account is expired. + ErrAccountExpired = ierrors.New("account expired") + // ErrInvalidSignature gets returned when the signature is invalid. + ErrInvalidSignature = ierrors.New("invalid signature") +) + +// Errors used for transaction failures. var ( // ErrUTXOInputInvalid gets returned when the UTXO input is invalid. ErrUTXOInputInvalid = ierrors.New("UTXO input is invalid") diff --git a/nodeclient/apimodels/core.go b/nodeclient/apimodels/core.go index cca1b3137..7ce6c1a91 100644 --- a/nodeclient/apimodels/core.go +++ b/nodeclient/apimodels/core.go @@ -51,16 +51,23 @@ func BlockStateFromBytes(b []byte) (BlockState, int, error) { } const ( - BlockFailureNone BlockFailureReason = 0 - BlockFailureIsTooOld BlockFailureReason = 1 - BlockFailureParentIsTooOld BlockFailureReason = 2 - BlockFailureParentNotFound BlockFailureReason = 3 - BlockFailureParentInvalid BlockFailureReason = 4 - BlockFailureDroppedDueToCongestion BlockFailureReason = 5 - BlockFailurePayloadInvalid BlockFailureReason = 6 + BlockFailureNone BlockFailureReason = 0 + BlockFailureIsTooOld BlockFailureReason = 1 + BlockFailureParentIsTooOld BlockFailureReason = 2 + BlockFailureParentNotFound BlockFailureReason = 3 + BlockFailureParentInvalid BlockFailureReason = 4 + BlockFailureIssuerAccountNotFound BlockFailureReason = 5 + BlockFailureVersionInvalid BlockFailureReason = 6 + BlockFailureManaCostCalculationFailed BlockFailureReason = 7 + BlockFailurBurnedInsufficientMana BlockFailureReason = 8 + BlockFailureAccountInvalid BlockFailureReason = 9 + BlockFailureSignatureInvalid BlockFailureReason = 10 + BlockFailureDroppedDueToCongestion BlockFailureReason = 11 + BlockFailurePayloadInvalid BlockFailureReason = 12 + BlockFailureInvalid BlockFailureReason = 255 // TODO: see if needed after congestion PR is done. - BlockFailureOrphanedDueNegativeCreditsBalance BlockFailureReason = 6 + BlockFailureOrphanedDueNegativeCreditsBalance BlockFailureReason = 13 ) func (t BlockFailureReason) Bytes() ([]byte, error) {