Skip to content

Commit

Permalink
Merge pull request #572 from iotaledger/feat/block-issuance-api
Browse files Browse the repository at this point in the history
Extend block issuance API
  • Loading branch information
karimodm authored Oct 19, 2023
2 parents bdd60ae + 4720279 commit 1d4b74e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
21 changes: 21 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 15 additions & 8 deletions nodeclient/apimodels/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions nodeclient/http_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -540,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[:]))

Expand Down

0 comments on commit 1d4b74e

Please sign in to comment.