Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend block issuance API #572

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading