diff --git a/components/inx/server_blocks.go b/components/inx/server_blocks.go index 79df07e55..e41439fbb 100644 --- a/components/inx/server_blocks.go +++ b/components/inx/server_blocks.go @@ -10,7 +10,6 @@ import ( "github.com/iotaledger/hive.go/runtime/contextutils" "github.com/iotaledger/hive.go/runtime/event" "github.com/iotaledger/hive.go/runtime/workerpool" - "github.com/iotaledger/hive.go/serializer/v2/serix" inx "github.com/iotaledger/inx/go" "github.com/iotaledger/iota-core/pkg/blockfactory" "github.com/iotaledger/iota-core/pkg/protocol/engine/blocks" @@ -119,17 +118,7 @@ func (s *Server) ListenToConfirmedBlocks(_ *inx.NoParams, srv inx.INX_ListenToCo } func (s *Server) SubmitBlock(ctx context.Context, rawBlock *inx.RawBlock) (*inx.BlockId, error) { - version, _, err := iotago.VersionFromBytes(rawBlock.GetData()) - if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "failed to parse block version: %s", err.Error()) - } - - apiForVersion, err := deps.Protocol.APIForVersion(version) - if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid block version: %s", err.Error()) - } - - block, err := rawBlock.UnwrapBlock(apiForVersion, serix.WithValidation()) + block, err := rawBlock.UnwrapBlock(deps.Protocol) if err != nil { return nil, err } @@ -137,23 +126,6 @@ func (s *Server) SubmitBlock(ctx context.Context, rawBlock *inx.RawBlock) (*inx. return s.attachBlock(ctx, block) } -func (s *Server) SubmitPayload(ctx context.Context, rawPayload *inx.RawPayload) (*inx.BlockId, error) { - payload, err := rawPayload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation()) - if err != nil { - return nil, err - } - - mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped()) - defer mergedCtxCancel() - - block, err := deps.BlockIssuer.CreateBlock(mergedCtx, blockIssuerAccount, blockfactory.WithPayload(payload)) - if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "failed to create block: %s", err.Error()) - } - - return s.attachBlock(ctx, block.ProtocolBlock()) -} - func (s *Server) attachBlock(ctx context.Context, block *iotago.ProtocolBlock) (*inx.BlockId, error) { mergedCtx, mergedCtxCancel := contextutils.MergeContexts(ctx, Component.Daemon().ContextStopped()) defer mergedCtxCancel() diff --git a/components/inx/server_tips.go b/components/inx/server_tips.go new file mode 100644 index 000000000..ee107263f --- /dev/null +++ b/components/inx/server_tips.go @@ -0,0 +1,18 @@ +package inx + +import ( + "context" + + inx "github.com/iotaledger/inx/go" + iotago "github.com/iotaledger/iota.go/v4" +) + +func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) { + references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(int(req.GetCount())) + + return &inx.TipsResponse{ + StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]), + WeakTips: inx.NewBlockIds(references[iotago.WeakParentType]), + ShallowLikeTips: inx.NewBlockIds(references[iotago.ShallowLikeParentType]), + }, nil +} diff --git a/go.mod b/go.mod index eba61647f..54d8af2af 100644 --- a/go.mod +++ b/go.mod @@ -24,9 +24,9 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65 github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65 github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 - github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9 - github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 - github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d + github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 + github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd + github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d github.com/labstack/echo/v4 v4.11.1 github.com/labstack/gommon v0.4.0 github.com/libp2p/go-libp2p v0.30.0 diff --git a/go.sum b/go.sum index ba121ee06..53a194994 100644 --- a/go.sum +++ b/go.sum @@ -301,12 +301,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36 github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9 h1:vRGNfCcC7xwqQP0WKNQrtfBarx4y3tTnpfljmgOTMG4= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9/go.mod h1:KbmEuxbhax3fyVrxF4RjBD1/MWLFxHLNDFBnDYUzok4= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 h1:YHvgNY3/TRx84UxqizkFe7vVUxAMQB2DOuEL8wjHxpg= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132/go.mod h1:DIFr5lt73HLIyn/Lg2jtzfakwhIT0mMZjMFFji3GXeI= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d h1:YvE8rOrBJQu9wryUAOwEEl4mu91rpocO23qKpffKdi8= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQiktl3Q0B+cHbVum7WzJikOEP+buw686oSrw5Unyz8= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d h1:lhYbBhVORcS2LLNviaO/yTmom1suDskJLA1wSvvsLiU= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= diff --git a/pkg/tests/accounts_test.go b/pkg/tests/accounts_test.go index 9b946801a..057e7a51a 100644 --- a/pkg/tests/accounts_test.go +++ b/pkg/tests/accounts_test.go @@ -65,7 +65,7 @@ func Test_TransitionAccount(t *testing.T) { accountInput, accountOutputs, accountWallets := ts.TransactionFramework.TransitionAccount( "Genesis:1", - testsuite.AddBlockIssuerKey(newGenesisOutputKey), + testsuite.WithAddBlockIssuerKey(newGenesisOutputKey), testsuite.WithBlockIssuerExpirySlot(1), ) consumedInputs, equalOutputs, equalWallets := ts.TransactionFramework.CreateBasicOutputsEqually(2, "Genesis:0") @@ -127,16 +127,8 @@ func Test_TransitionAccount(t *testing.T) { &iotago.StateControllerAddressUnlockCondition{Address: ts.TransactionFramework.DefaultAddress()}, &iotago.GovernorAddressUnlockCondition{Address: ts.TransactionFramework.DefaultAddress()}, }), - testsuite.WithBlockIssuerFeature(&iotago.BlockIssuerFeature{ - BlockIssuerKeys: iotago.NewBlockIssuerKeys(newAccountBlockIssuerKey), - ExpirySlot: newAccountExpirySlot, - }), - testsuite.WithStakingFeature(&iotago.StakingFeature{ - StakedAmount: 10000, - FixedCost: 421, - StartEpoch: 0, - EndEpoch: 10, - }), + testsuite.WithBlockIssuerFeature(iotago.BlockIssuerKeys{newAccountBlockIssuerKey}, newAccountExpirySlot), + testsuite.WithStakingFeature(10000, 421, 0, 10), ) destroyedAccountInput, destructionOutputs, destroyWallets := ts.TransactionFramework.DestroyAccount("TX1:0") diff --git a/pkg/testsuite/transactions_framework.go b/pkg/testsuite/transactions_framework.go index aaffe1e68..eea7bc2e7 100644 --- a/pkg/testsuite/transactions_framework.go +++ b/pkg/testsuite/transactions_framework.go @@ -175,20 +175,14 @@ func (t *TransactionFramework) CreateBasicOutputs(amountDistribution []iotago.Ba return inputStates, outputStates, []*mock.HDWallet{t.wallet} } -func (t *TransactionFramework) CreateAccountFromInput(inputAlias string, opts ...options.Option[iotago.AccountOutput]) (utxoledger.Outputs, iotago.Outputs[iotago.Output], []*mock.HDWallet) { +func (t *TransactionFramework) CreateAccountFromInput(inputAlias string, opts ...options.Option[builder.AccountOutputBuilder]) (utxoledger.Outputs, iotago.Outputs[iotago.Output], []*mock.HDWallet) { input := t.Output(inputAlias) - accountOutput := options.Apply(&iotago.AccountOutput{ - Amount: input.BaseTokenAmount(), - Mana: input.StoredMana(), - NativeTokens: iotago.NativeTokens{}, - Conditions: iotago.AccountOutputUnlockConditions{ - &iotago.StateControllerAddressUnlockCondition{Address: t.DefaultAddress()}, - &iotago.GovernorAddressUnlockCondition{Address: t.DefaultAddress()}, - }, - Features: iotago.AccountOutputFeatures{}, - ImmutableFeatures: iotago.AccountOutputImmFeatures{}, - }, opts) + accountOutput := options.Apply(builder.NewAccountOutputBuilder(t.DefaultAddress(), t.DefaultAddress(), input.BaseTokenAmount()). + Mana(input.StoredMana()). + StateController(t.DefaultAddress()). + Governor(t.DefaultAddress()), + opts).MustBuild() outputStates := iotago.Outputs[iotago.Output]{accountOutput} @@ -211,20 +205,12 @@ func (t *TransactionFramework) CreateAccountFromInput(inputAlias string, opts .. // CreateDelegationFromInput creates a new DelegationOutput with given options from an input. If the remainder Output // is not created, then StoredMana from the input is not passed and can potentially be burned. // In order not to burn it, it needs to be assigned manually in another output in the transaction. -func (t *TransactionFramework) CreateDelegationFromInput(inputAlias string, opts ...options.Option[iotago.DelegationOutput]) (utxoledger.Outputs, iotago.Outputs[iotago.Output], []*mock.HDWallet) { +func (t *TransactionFramework) CreateDelegationFromInput(inputAlias string, opts ...options.Option[builder.DelegationOutputBuilder]) (utxoledger.Outputs, iotago.Outputs[iotago.Output], []*mock.HDWallet) { input := t.Output(inputAlias) - delegationOutput := options.Apply(&iotago.DelegationOutput{ - Amount: input.BaseTokenAmount(), - DelegatedAmount: input.BaseTokenAmount(), - DelegationID: iotago.DelegationID{}, - ValidatorAddress: &iotago.AccountAddress{}, - StartEpoch: 0, - EndEpoch: 0, - Conditions: iotago.DelegationOutputUnlockConditions{ - &iotago.AddressUnlockCondition{Address: t.DefaultAddress()}, - }, - }, opts) + delegationOutput := options.Apply(builder.NewDelegationOutputBuilder(&iotago.AccountAddress{}, t.DefaultAddress(), input.BaseTokenAmount()). + DelegatedAmount(input.BaseTokenAmount()), + opts).MustBuild() if delegationOutput.ValidatorAddress.AccountID() == iotago.EmptyAccountID() || delegationOutput.DelegatedAmount == 0 || @@ -257,17 +243,17 @@ func (t *TransactionFramework) DelayedClaimingTransition(inputAlias string, dele panic(ierrors.Errorf("%s is not a delegation output, cannot transition to delayed claiming state", inputAlias)) } - delegationOutput, ok := input.Output().Clone().(*iotago.DelegationOutput) + prevOutput, ok := input.Output().Clone().(*iotago.DelegationOutput) if !ok { panic(ierrors.Errorf("cloned output %s is not a delegation output, cannot transition to delayed claiming state", inputAlias)) } - if delegationOutput.DelegationID == iotago.EmptyDelegationID() { - delegationOutput.DelegationID = iotago.DelegationIDFromOutputID(input.OutputID()) + delegationBuilder := builder.NewDelegationOutputBuilderFromPrevious(prevOutput).EndEpoch(delegationEndEpoch) + if prevOutput.DelegationID == iotago.EmptyDelegationID() { + delegationBuilder.DelegationID(iotago.DelegationIDFromOutputID(input.OutputID())) } - delegationOutput.EndEpoch = delegationEndEpoch - return utxoledger.Outputs{input}, iotago.Outputs[iotago.Output]{delegationOutput}, []*mock.HDWallet{t.wallet} + return utxoledger.Outputs{input}, iotago.Outputs[iotago.Output]{delegationBuilder.MustBuild()}, []*mock.HDWallet{t.wallet} } func (t *TransactionFramework) DestroyAccount(alias string) (consumedInputs *utxoledger.Output, outputs iotago.Outputs[iotago.Output], signingWallets []*mock.HDWallet) { @@ -286,7 +272,7 @@ func (t *TransactionFramework) DestroyAccount(alias string) (consumedInputs *utx return output, outputStates, []*mock.HDWallet{t.wallet} } -func (t *TransactionFramework) TransitionAccount(alias string, opts ...options.Option[iotago.AccountOutput]) (consumedInput *utxoledger.Output, outputs iotago.Outputs[iotago.Output], signingWallets []*mock.HDWallet) { +func (t *TransactionFramework) TransitionAccount(alias string, opts ...options.Option[builder.AccountOutputBuilder]) (consumedInput *utxoledger.Output, outputs iotago.Outputs[iotago.Output], signingWallets []*mock.HDWallet) { output, exists := t.states[alias] if !exists { panic(fmt.Sprintf("account with alias %s does not exist", alias)) @@ -297,7 +283,8 @@ func (t *TransactionFramework) TransitionAccount(alias string, opts ...options.O panic(fmt.Sprintf("output with alias %s is not *iotago.AccountOutput", alias)) } - accountOutput = options.Apply(accountOutput, opts) + accountBuilder := builder.NewAccountOutputBuilderFromPrevious(accountOutput) + accountOutput = options.Apply(accountBuilder, opts).MustBuild() return output, iotago.Outputs[iotago.Output]{accountOutput}, []*mock.HDWallet{t.wallet} } @@ -342,159 +329,130 @@ func (t *TransactionFramework) DefaultAddress() iotago.Address { // DelegationOutput options -func WithDelegatedAmount(delegatedAmount iotago.BaseToken) options.Option[iotago.DelegationOutput] { - return func(delegationOutput *iotago.DelegationOutput) { - delegationOutput.DelegatedAmount = delegatedAmount +func WithDelegatedAmount(delegatedAmount iotago.BaseToken) options.Option[builder.DelegationOutputBuilder] { + return func(delegationBuilder *builder.DelegationOutputBuilder) { + delegationBuilder.DelegatedAmount(delegatedAmount) } } -func WithDelegatedValidatorAddress(validatorAddress *iotago.AccountAddress) options.Option[iotago.DelegationOutput] { - return func(delegationOutput *iotago.DelegationOutput) { - delegationOutput.ValidatorAddress = validatorAddress +func WithDelegatedValidatorAddress(validatorAddress *iotago.AccountAddress) options.Option[builder.DelegationOutputBuilder] { + return func(delegationBuilder *builder.DelegationOutputBuilder) { + delegationBuilder.ValidatorAddress(validatorAddress) } } -func WithDelegationStartEpoch(startEpoch iotago.EpochIndex) options.Option[iotago.DelegationOutput] { - return func(delegationOutput *iotago.DelegationOutput) { - delegationOutput.StartEpoch = startEpoch +func WithDelegationStartEpoch(startEpoch iotago.EpochIndex) options.Option[builder.DelegationOutputBuilder] { + return func(delegationBuilder *builder.DelegationOutputBuilder) { + delegationBuilder.StartEpoch(startEpoch) } } -func WithDelegationEndEpoch(endEpoch iotago.EpochIndex) options.Option[iotago.DelegationOutput] { - return func(delegationOutput *iotago.DelegationOutput) { - delegationOutput.EndEpoch = endEpoch +func WithDelegationEndEpoch(endEpoch iotago.EpochIndex) options.Option[builder.DelegationOutputBuilder] { + return func(delegationBuilder *builder.DelegationOutputBuilder) { + delegationBuilder.EndEpoch(endEpoch) } } -func WithDelegationConditions(delegationConditions iotago.DelegationOutputUnlockConditions) options.Option[iotago.DelegationOutput] { - return func(delegationOutput *iotago.DelegationOutput) { - delegationOutput.Conditions = delegationConditions +func WithDelegationConditions(delegationConditions iotago.DelegationOutputUnlockConditions) options.Option[builder.DelegationOutputBuilder] { + return func(delegationBuilder *builder.DelegationOutputBuilder) { + delegationBuilder.Address(delegationConditions.MustSet().Address().Address) } } -func WithDelegationAmount(amount iotago.BaseToken) options.Option[iotago.DelegationOutput] { - return func(delegationOutput *iotago.DelegationOutput) { - delegationOutput.Amount = amount +func WithDelegationAmount(amount iotago.BaseToken) options.Option[builder.DelegationOutputBuilder] { + return func(delegationBuilder *builder.DelegationOutputBuilder) { + delegationBuilder.Amount(amount) } } // BlockIssuer options -func WithBlockIssuerFeature(blockIssuerFeature *iotago.BlockIssuerFeature) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - for idx, feature := range accountOutput.Features { - if feature.Type() == iotago.FeatureBlockIssuer { - accountOutput.Features[idx] = blockIssuerFeature - return - } - } - - accountOutput.Features = append(accountOutput.Features, blockIssuerFeature) +func WithBlockIssuerFeature(keys iotago.BlockIssuerKeys, expirySlot iotago.SlotIndex) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + accountBuilder.BlockIssuer(keys, expirySlot) } } -func AddBlockIssuerKey(key iotago.BlockIssuerKey) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - blockIssuer := accountOutput.FeatureSet().BlockIssuer() - if blockIssuer == nil { - panic("cannot add block issuer key to account without BlockIssuer feature") - } - blockIssuer.BlockIssuerKeys = append(blockIssuer.BlockIssuerKeys, key) - - blockIssuer.BlockIssuerKeys.Sort() +func WithAddBlockIssuerKey(key iotago.BlockIssuerKey) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + transition := accountBuilder.GovernanceTransition() + transition.BlockIssuerTransition().AddKeys(key) } } -func WithBlockIssuerKeys(keys iotago.BlockIssuerKeys) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - blockIssuer := accountOutput.FeatureSet().BlockIssuer() - if blockIssuer == nil { - panic("cannot set block issuer keys to account without BlockIssuer feature") - } - blockIssuer.BlockIssuerKeys = keys - } -} - -func WithBlockIssuerExpirySlot(expirySlot iotago.SlotIndex) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - blockIssuer := accountOutput.FeatureSet().BlockIssuer() - if blockIssuer == nil { - panic("cannot set block issuer expiry slot to account without BlockIssuer feature") - } - blockIssuer.ExpirySlot = expirySlot +func WithBlockIssuerKeys(keys iotago.BlockIssuerKeys) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + transition := accountBuilder.GovernanceTransition() + transition.BlockIssuerTransition().Keys(keys) } } -func WithStakingFeature(stakingFeature *iotago.StakingFeature) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - for idx, feature := range accountOutput.Features { - if feature.Type() == iotago.FeatureStaking { - accountOutput.Features[idx] = stakingFeature - return - } - } - - accountOutput.Features = append(accountOutput.Features, stakingFeature) +func WithBlockIssuerExpirySlot(expirySlot iotago.SlotIndex) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + transition := accountBuilder.GovernanceTransition() + transition.BlockIssuerTransition().ExpirySlot(expirySlot) } } -func WithStakingEndEpoch(endEpoch iotago.EpochIndex) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - staking := accountOutput.FeatureSet().Staking() - if staking == nil { - panic("cannot update staking end epoch on account without Staking feature") - } - staking.EndEpoch = endEpoch +func WithStakingFeature(amount iotago.BaseToken, fixedCost iotago.Mana, startEpoch iotago.EpochIndex, optEndEpoch ...iotago.EpochIndex) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + accountBuilder.Staking(amount, fixedCost, startEpoch, optEndEpoch...) } } // Account options -func WithAccountMana(mana iotago.Mana) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.Mana = mana - } -} - -func WithAccountAmount(amount iotago.BaseToken) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.Amount = amount +func WithAccountMana(mana iotago.Mana) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + accountBuilder.Mana(mana) } } -func WithAccountIncreasedStateIndex() options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.StateIndex++ +func WithAccountAmount(amount iotago.BaseToken) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + accountBuilder.Amount(amount) } } -func WithAccountIncreasedFoundryCounter(diff uint32) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.FoundryCounter += diff +func WithAccountIncreasedFoundryCounter(diff uint32) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + accountBuilder.FoundriesToGenerate(diff) } } -func WithAccountFeatures(features iotago.AccountOutputFeatures) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.Features = features - } -} - -func WithAccountImmutableFeatures(features iotago.AccountOutputImmFeatures) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.ImmutableFeatures = features +func WithAccountImmutableFeatures(features iotago.AccountOutputImmFeatures) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + for _, feature := range features.MustSet() { + switch feature.Type() { + case iotago.FeatureMetadata: + //nolint:forcetypeassert + accountBuilder.ImmutableMetadata(feature.(*iotago.MetadataFeature).Data) + case iotago.FeatureSender: + //nolint:forcetypeassert + accountBuilder.ImmutableSender(feature.(*iotago.SenderFeature).Address) + } + } } } -func WithAccountConditions(conditions iotago.AccountOutputUnlockConditions) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.Conditions = conditions +func WithAccountConditions(conditions iotago.AccountOutputUnlockConditions) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + for _, condition := range conditions.MustSet() { + switch condition.Type() { + case iotago.UnlockConditionStateControllerAddress: + //nolint:forcetypeassert + accountBuilder.StateController(condition.(*iotago.StateControllerAddressUnlockCondition).Address) + case iotago.UnlockConditionGovernorAddress: + //nolint:forcetypeassert + accountBuilder.Governor(condition.(*iotago.GovernorAddressUnlockCondition).Address) + } + } } } -func WithAccountNativeTokens(nativeTokens iotago.NativeTokens) options.Option[iotago.AccountOutput] { - return func(accountOutput *iotago.AccountOutput) { - accountOutput.NativeTokens = nativeTokens +func WithAccountNativeTokens(nativeTokens iotago.NativeTokens) options.Option[builder.AccountOutputBuilder] { + return func(accountBuilder *builder.AccountOutputBuilder) { + accountBuilder.NativeTokens(nativeTokens) } } diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index 88d92ecfc..861cfb4a5 100644 --- a/tools/evil-spammer/go.mod +++ b/tools/evil-spammer/go.mod @@ -17,7 +17,7 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65 github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 github.com/iotaledger/iota-core/tools/genesis-snapshot v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d + github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d github.com/mr-tron/base58 v1.2.0 go.uber.org/atomic v1.11.0 ) diff --git a/tools/evil-spammer/go.sum b/tools/evil-spammer/go.sum index b4ba98def..9138a9753 100644 --- a/tools/evil-spammer/go.sum +++ b/tools/evil-spammer/go.sum @@ -195,8 +195,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36 github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d h1:YvE8rOrBJQu9wryUAOwEEl4mu91rpocO23qKpffKdi8= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d h1:lhYbBhVORcS2LLNviaO/yTmom1suDskJLA1wSvvsLiU= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index 5c88f689e..e67b05610 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -70,9 +70,9 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65 // indirect github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65 // indirect github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 // indirect - github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9 // indirect - github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 // indirect - github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d // indirect + github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 // indirect + github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd // indirect + github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d // indirect github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 5da500e26..5edeea70e 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -307,12 +307,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36 github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9 h1:vRGNfCcC7xwqQP0WKNQrtfBarx4y3tTnpfljmgOTMG4= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927112840-e982cb6707c9/go.mod h1:KbmEuxbhax3fyVrxF4RjBD1/MWLFxHLNDFBnDYUzok4= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132 h1:YHvgNY3/TRx84UxqizkFe7vVUxAMQB2DOuEL8wjHxpg= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230925152824-4bfa09b8c132/go.mod h1:DIFr5lt73HLIyn/Lg2jtzfakwhIT0mMZjMFFji3GXeI= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d h1:YvE8rOrBJQu9wryUAOwEEl4mu91rpocO23qKpffKdi8= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQiktl3Q0B+cHbVum7WzJikOEP+buw686oSrw5Unyz8= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d h1:lhYbBhVORcS2LLNviaO/yTmom1suDskJLA1wSvvsLiU= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index 6d2734219..b75541880 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -10,7 +10,7 @@ require ( github.com/iotaledger/hive.go/lo v0.0.0-20230926122307-d671b36a4a65 github.com/iotaledger/hive.go/runtime v0.0.0-20230926122307-d671b36a4a65 github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d + github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d github.com/mr-tron/base58 v1.2.0 github.com/spf13/pflag v1.0.5 golang.org/x/crypto v0.13.0 diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index 22f1d5f55..1b24bf02e 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -50,8 +50,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36 github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230926122307-d671b36a4a65/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65 h1:3OmUR8yYlCENhbosY99eM3bIJQJCiLijtebt+Q6sQEs= github.com/iotaledger/hive.go/stringify v0.0.0-20230926122307-d671b36a4a65/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d h1:YvE8rOrBJQu9wryUAOwEEl4mu91rpocO23qKpffKdi8= -github.com/iotaledger/iota.go/v4 v4.0.0-20230928093005-fe74b3839c5d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d h1:lhYbBhVORcS2LLNviaO/yTmom1suDskJLA1wSvvsLiU= +github.com/iotaledger/iota.go/v4 v4.0.0-20230927125610-ddf51789ec4d/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=