From 66d9ef2b0ff58d0b0ff365ef4470f03e32835497 Mon Sep 17 00:00:00 2001 From: muXxer Date: Mon, 9 Oct 2023 19:19:04 +0200 Subject: [PATCH] Add return value to SendPayloadWithTransactionBuilder --- go.mod | 1 - go.sum | 2 -- nodeclient/blockissuer_client.go | 23 ++++++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index ece87be08..2e4fb70c3 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,6 @@ require ( github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/holiman/uint256 v1.2.3 // indirect github.com/iancoleman/orderedmap v0.3.0 // indirect - github.com/iotaledger/hive.go/codegen v0.0.0-20231005142627-86973b2edb3b // indirect github.com/kr/text v0.2.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/go.sum b/go.sum index 37ff8d311..e06d4a86a 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,6 @@ github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= -github.com/iotaledger/hive.go/codegen v0.0.0-20231005142627-86973b2edb3b h1:RpCqfmmxrkTdxPm56UzF1QuHppTo3VtyzhfaUUfzVA0= -github.com/iotaledger/hive.go/codegen v0.0.0-20231005142627-86973b2edb3b/go.mod h1:zBiQaY4DL7xx/gNgb1MWqMaV62x2o937nBCEaW++ztI= github.com/iotaledger/hive.go/constraints v0.0.0-20231005142627-86973b2edb3b h1:8FdKoB755PjCL1aHTi+2rPt9lCUS4B2wg2fNKykw5dc= github.com/iotaledger/hive.go/constraints v0.0.0-20231005142627-86973b2edb3b/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s= github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231005142627-86973b2edb3b h1:gQ+Wqg8h/LRpgX3CsmaOZYdMIBVL4fAPIrZbmA6Wn3Q= diff --git a/nodeclient/blockissuer_client.go b/nodeclient/blockissuer_client.go index 3cebf1be2..7bab413df 100644 --- a/nodeclient/blockissuer_client.go +++ b/nodeclient/blockissuer_client.go @@ -33,7 +33,7 @@ type ( // SendPayload sends a BlockPayload to the block issuer. SendPayload(ctx context.Context, payload iotago.BlockPayload, commitmentID iotago.CommitmentID, numPoWWorkers ...int) (*apimodels.BlockCreatedResponse, error) // SendPayloadWithTransactionBuilder automatically allots the needed mana and sends a BlockPayload to the block issuer. - SendPayloadWithTransactionBuilder(ctx context.Context, builder *builder.TransactionBuilder, signer iotago.AddressSigner, storedManaOutputIndex int, numPoWWorkers ...int) (*apimodels.BlockCreatedResponse, error) + SendPayloadWithTransactionBuilder(ctx context.Context, builder *builder.TransactionBuilder, signer iotago.AddressSigner, storedManaOutputIndex int, numPoWWorkers ...int) (iotago.BlockPayload, *apimodels.BlockCreatedResponse, error) } blockIssuerClient struct { @@ -112,31 +112,31 @@ func (client *blockIssuerClient) SendPayload(ctx context.Context, payload iotago return client.mineNonceAndSendPayload(ctx, payload, commitmentID, blockIssuerInfo.PowTargetTrailingZeros, numPoWWorkers...) } -func (client *blockIssuerClient) SendPayloadWithTransactionBuilder(ctx context.Context, builder *builder.TransactionBuilder, signer iotago.AddressSigner, storedManaOutputIndex int, numPoWWorkers ...int) (*apimodels.BlockCreatedResponse, error) { +func (client *blockIssuerClient) SendPayloadWithTransactionBuilder(ctx context.Context, builder *builder.TransactionBuilder, signer iotago.AddressSigner, storedManaOutputIndex int, numPoWWorkers ...int) (iotago.BlockPayload, *apimodels.BlockCreatedResponse, error) { // get the info from the block issuer blockIssuerInfo, err := client.Info(ctx) if err != nil { - return nil, ierrors.Wrap(err, "failed to get the block issuer info") + return nil, nil, ierrors.Wrap(err, "failed to get the block issuer info") } // parse the block issuer address //nolint:contextcheck // false positive _, blockIssuerAddress, err := iotago.ParseBech32(blockIssuerInfo.BlockIssuerAddress) if err != nil { - return nil, ierrors.Wrap(err, "failed to parse the block issuer address") + return nil, nil, ierrors.Wrap(err, "failed to parse the block issuer address") } // check if the block issuer address is an account address blockIssuerAccountAddress, isAccount := blockIssuerAddress.(*iotago.AccountAddress) if !isAccount { - return nil, ierrors.New("failed to parse the block issuer address") + return nil, nil, ierrors.New("failed to parse the block issuer address") } // get the current commitmentID and reference mana cost to calculate // the correct value for the mana that needs to be alloted to the block issuer. blockIssuance, err := client.core.BlockIssuance(ctx) if err != nil { - return nil, ierrors.Wrap(err, "failed to get the latest block issuance infos") + return nil, nil, ierrors.Wrap(err, "failed to get the latest block issuance infos") } // allot the required mana to the block issuer @@ -145,14 +145,19 @@ func (client *blockIssuerClient) SendPayloadWithTransactionBuilder(ctx context.C // sign the transaction payload, err := builder.Build(signer) if err != nil { - return nil, ierrors.Wrap(err, "failed to build the signed transaction payload") + return nil, nil, ierrors.Wrap(err, "failed to build the signed transaction payload") } //nolint:contextcheck // false positive commitmentID, err := blockIssuance.Commitment.ID() if err != nil { - return nil, ierrors.Wrap(err, "failed to calculate the commitment ID") + return nil, nil, ierrors.Wrap(err, "failed to calculate the commitment ID") } - return client.mineNonceAndSendPayload(ctx, payload, commitmentID, blockIssuerInfo.PowTargetTrailingZeros, numPoWWorkers...) + blockCreatedResponse, err := client.mineNonceAndSendPayload(ctx, payload, commitmentID, blockIssuerInfo.PowTargetTrailingZeros, numPoWWorkers...) + if err != nil { + return nil, nil, err + } + + return payload, blockCreatedResponse, nil }