Skip to content

Commit

Permalink
Merge pull request #589 from iotaledger/feat/add-anchor-output
Browse files Browse the repository at this point in the history
Add AnchorOutput
  • Loading branch information
muXxer authored Oct 31, 2023
2 parents c52290b + 701e4cc commit 5d7d593
Show file tree
Hide file tree
Showing 24 changed files with 3,307 additions and 1,830 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
golangci-lint:
name: GolangCI-Lint
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test_and_benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ jobs:
strategy:
matrix:
go-version: [ "1.21.x" ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
platform: [ self-hosted ]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- name: Run tests
run: go test -v -covermode=count ./...

- name: Run Benchmarks
run: go test -bench=. ./...
4 changes: 2 additions & 2 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func runOutputsSyntacticalValidationTest(t *testing.T, testAPI iotago.API, test

func TestRestrictedAddressSyntacticalValidation(t *testing.T) {

defaultAmount := OneMi
defaultAmount := OneIOTA

tests := []*outputsSyntacticalValidationTest{
// ok - Valid address types nested inside of a RestrictedAddress
Expand Down Expand Up @@ -588,7 +588,7 @@ func TestRestrictedAddressSyntacticalValidation(t *testing.T) {

func TestMultiAddressSyntacticalValidation(t *testing.T) {

defaultAmount := OneMi
defaultAmount := OneIOTA

tests := []*outputsSyntacticalValidationTest{
// fail - threshold > cumulativeWeight
Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
OneMi iotago.BaseToken = 1_000_000
OneIOTA iotago.BaseToken = 1_000_000
)

type deSerializeTest struct {
Expand Down
108 changes: 85 additions & 23 deletions api_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func disallowImplicitAccountCreationAddress(address Address) error {

var (
basicOutputV3UnlockCondArrRules = &serix.ArrayRules{
Min: 1,
Max: 4,
Min: 1, // Min: AddressUnlockCondition
Max: 4, // Max: AddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition, ExpirationUnlockCondition
MustOccur: serializer.TypePrefixes{
uint32(UnlockConditionAddress): struct{}{},
},
Expand All @@ -42,42 +42,71 @@ var (
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}
basicOutputV3FeatBlocksArrRules = &serix.ArrayRules{
Min: 0,
Max: 4,
Min: 0, // Min: -
Max: 4, // Max: SenderFeature, MetadataFeature, TagFeature, NativeTokenFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

accountOutputV3UnlockCondArrRules = &serix.ArrayRules{
Min: 2, Max: 2,
Min: 1, // Min: AddressUnlockCondition
Max: 1, // Max: AddressUnlockCondition
MustOccur: serializer.TypePrefixes{
uint32(UnlockConditionStateControllerAddress): struct{}{},
uint32(UnlockConditionGovernorAddress): struct{}{},
uint32(UnlockConditionAddress): struct{}{},
},
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

accountOutputV3FeatBlocksArrRules = &serix.ArrayRules{
Min: 0,
Max: 4,
Min: 0, // Min: -
Max: 4, // Max: SenderFeature, MetadataFeature, BlockIssuerFeature, StakingFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

accountOutputV3ImmFeatBlocksArrRules = &serix.ArrayRules{
Min: 0,
Max: 2,
Min: 0, // Min: -
Max: 2, // Max: IssuerFeature, MetadataFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

anchorOutputV3UnlockCondArrRules = &serix.ArrayRules{
Min: 2, // Min: StateControllerAddressUnlockCondition, GovernorAddressUnlockCondition
Max: 2, // Max: StateControllerAddressUnlockCondition, GovernorAddressUnlockCondition
MustOccur: serializer.TypePrefixes{
uint32(UnlockConditionStateControllerAddress): struct{}{},
uint32(UnlockConditionGovernorAddress): struct{}{},
},
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

anchorOutputV3FeatBlocksArrRules = &serix.ArrayRules{
Min: 0, // Min: -
Max: 2, // Max: SenderFeature, MetadataFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

anchorOutputV3ImmFeatBlocksArrRules = &serix.ArrayRules{
Min: 0, // Min: -
Max: 2, // Max: IssuerFeature, MetadataFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

foundryOutputV3UnlockCondArrRules = &serix.ArrayRules{
Min: 1, Max: 1,
Min: 1, // Min: ImmutableAccountUnlockCondition
Max: 1, // Max: ImmutableAccountUnlockCondition
MustOccur: serializer.TypePrefixes{
uint32(UnlockConditionImmutableAccount): struct{}{},
},
Expand All @@ -87,21 +116,24 @@ var (
}

foundryOutputV3FeatBlocksArrRules = &serix.ArrayRules{
Min: 0, Max: 2,
Min: 0, // Min: -
Max: 2, // Max: MetadataFeature, NativeTokenFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

foundryOutputV3ImmFeatBlocksArrRules = &serix.ArrayRules{
Min: 0, Max: 1,
Min: 0, // Min: -
Max: 1, // Max: MetadataFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

nftOutputV3UnlockCondArrRules = &serix.ArrayRules{
Min: 1, Max: 4,
Min: 1, // Min: AddressUnlockCondition
Max: 4, // Max: AddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition, ExpirationUnlockCondition
MustOccur: serializer.TypePrefixes{
uint32(UnlockConditionAddress): struct{}{},
},
Expand All @@ -111,23 +143,24 @@ var (
}

nftOutputV3FeatBlocksArrRules = &serix.ArrayRules{
Min: 0,
Max: 3,
Min: 0, // Min: -
Max: 3, // Max: SenderFeature, MetadataFeature, TagFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

nftOutputV3ImmFeatBlocksArrRules = &serix.ArrayRules{
Min: 0,
Max: 2,
Min: 0, // Min: -
Max: 2, // Max: IssuerFeature, MetadataFeature
ValidationMode: serializer.ArrayValidationModeNoDuplicates |
serializer.ArrayValidationModeLexicalOrdering |
serializer.ArrayValidationModeAtMostOneOfEachTypeByte,
}

delegationOutputV3UnlockCondArrRules = &serix.ArrayRules{
Min: 1, Max: 1,
Min: 1, // Min: AddressUnlockCondition
Max: 1, // Max: AddressUnlockCondition
MustOccur: serializer.TypePrefixes{
uint32(UnlockConditionAddress): struct{}{},
},
Expand Down Expand Up @@ -163,7 +196,8 @@ var (
}

txV3UnlocksArrRules = &serix.ArrayRules{
Min: 1, Max: MaxInputsCount,
Min: 1,
Max: MaxInputsCount,
}

blockIDsArrRules = &serix.ArrayRules{
Expand Down Expand Up @@ -430,8 +464,7 @@ func V3API(protoParams ProtocolParameters) API {
serix.TypeSettings{}.WithLengthPrefixType(serix.LengthPrefixTypeAsByte).WithArrayRules(accountOutputV3UnlockCondArrRules),
))

must(api.RegisterInterfaceObjects((*accountOutputUnlockCondition)(nil), (*StateControllerAddressUnlockCondition)(nil)))
must(api.RegisterInterfaceObjects((*accountOutputUnlockCondition)(nil), (*GovernorAddressUnlockCondition)(nil)))
must(api.RegisterInterfaceObjects((*accountOutputUnlockCondition)(nil), (*AddressUnlockCondition)(nil)))

must(api.RegisterTypeSettings(AccountOutputFeatures{},
serix.TypeSettings{}.WithLengthPrefixType(serix.LengthPrefixTypeAsByte).WithArrayRules(accountOutputV3FeatBlocksArrRules),
Expand All @@ -450,6 +483,34 @@ func V3API(protoParams ProtocolParameters) API {
must(api.RegisterInterfaceObjects((*accountOutputImmFeature)(nil), (*MetadataFeature)(nil)))
}

{
must(api.RegisterTypeSettings(AnchorOutput{}, serix.TypeSettings{}.WithObjectType(uint8(OutputAnchor))))
must(api.RegisterValidators(AnchorOutput{}, nil, func(ctx context.Context, anchor AnchorOutput) error {
return anchor.syntacticallyValidate()
}))

must(api.RegisterTypeSettings(AnchorOutputUnlockConditions{},
serix.TypeSettings{}.WithLengthPrefixType(serix.LengthPrefixTypeAsByte).WithArrayRules(anchorOutputV3UnlockCondArrRules),
))

must(api.RegisterInterfaceObjects((*anchorOutputUnlockCondition)(nil), (*StateControllerAddressUnlockCondition)(nil)))
must(api.RegisterInterfaceObjects((*anchorOutputUnlockCondition)(nil), (*GovernorAddressUnlockCondition)(nil)))

must(api.RegisterTypeSettings(AnchorOutputFeatures{},
serix.TypeSettings{}.WithLengthPrefixType(serix.LengthPrefixTypeAsByte).WithArrayRules(anchorOutputV3FeatBlocksArrRules),
))

must(api.RegisterInterfaceObjects((*anchorOutputFeature)(nil), (*SenderFeature)(nil)))
must(api.RegisterInterfaceObjects((*anchorOutputFeature)(nil), (*MetadataFeature)(nil)))

must(api.RegisterTypeSettings(AnchorOutputImmFeatures{},
serix.TypeSettings{}.WithLengthPrefixType(serix.LengthPrefixTypeAsByte).WithArrayRules(anchorOutputV3ImmFeatBlocksArrRules),
))

must(api.RegisterInterfaceObjects((*anchorOutputImmFeature)(nil), (*IssuerFeature)(nil)))
must(api.RegisterInterfaceObjects((*anchorOutputImmFeature)(nil), (*MetadataFeature)(nil)))
}

{
must(api.RegisterTypeSettings(FoundryOutput{},
serix.TypeSettings{}.WithObjectType(uint8(OutputFoundry))),
Expand Down Expand Up @@ -569,6 +630,7 @@ func V3API(protoParams ProtocolParameters) API {

must(api.RegisterInterfaceObjects((*TxEssenceOutput)(nil), (*BasicOutput)(nil)))
must(api.RegisterInterfaceObjects((*TxEssenceOutput)(nil), (*AccountOutput)(nil)))
must(api.RegisterInterfaceObjects((*TxEssenceOutput)(nil), (*AnchorOutput)(nil)))
must(api.RegisterInterfaceObjects((*TxEssenceOutput)(nil), (*DelegationOutput)(nil)))
must(api.RegisterInterfaceObjects((*TxEssenceOutput)(nil), (*FoundryOutput)(nil)))
must(api.RegisterInterfaceObjects((*TxEssenceOutput)(nil), (*NFTOutput)(nil)))
Expand Down
Loading

0 comments on commit 5d7d593

Please sign in to comment.