Skip to content

Commit

Permalink
Merge pull request #699 from iotaledger/chore/rename-ident
Browse files Browse the repository at this point in the history
Rename Ident to owner/address and Ref to Reference/Referential unlocks
  • Loading branch information
muXxer authored Feb 26, 2024
2 parents 70d23c1 + 46f9503 commit 7aa8e85
Show file tree
Hide file tree
Showing 35 changed files with 1,017 additions and 1,016 deletions.
12 changes: 6 additions & 6 deletions builder/transaction_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
)

func TestTransactionBuilder(t *testing.T) {
identityOne := tpkg.RandEd25519PrivateKey()
prvKey := tpkg.RandEd25519PrivateKey()
//nolint:forcetypeassert // we can safely assume that this is an ed25519.PublicKey
inputAddr := iotago.Ed25519AddressFromPubKey(identityOne.Public().(ed25519.PublicKey))
addrKeys := iotago.AddressKeys{Address: inputAddr, Keys: identityOne}
inputAddr := iotago.Ed25519AddressFromPubKey(prvKey.Public().(ed25519.PublicKey))
addrKeys := iotago.AddressKeys{Address: inputAddr, Keys: prvKey}

type test struct {
name string
Expand Down Expand Up @@ -138,10 +138,10 @@ func TestTransactionBuilder(t *testing.T) {
})

// wrong address/keys
wrongIdentity := tpkg.RandEd25519PrivateKey()
wrongAddress := tpkg.RandEd25519PrivateKey()
//nolint:forcetypeassert // we can safely assume that this is a ed25519.PublicKey
wrongAddr := iotago.Ed25519AddressFromPubKey(wrongIdentity.Public().(ed25519.PublicKey))
wrongAddrKeys := iotago.AddressKeys{Address: wrongAddr, Keys: wrongIdentity}
wrongAddr := iotago.Ed25519AddressFromPubKey(wrongAddress.Public().(ed25519.PublicKey))
wrongAddrKeys := iotago.AddressKeys{Address: wrongAddr, Keys: wrongAddress}

return &test{
name: "err - missing address keys (wrong address)",
Expand Down
4 changes: 2 additions & 2 deletions feat_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

// IssuerFeature is a feature which associates an output
// with an issuer identity. Unlike the SenderFeature, the issuer identity
// with an issuer address. Unlike the SenderFeature, the issuer address
// only has to be unlocked when the ChainOutput is first created,
// afterwards, the issuer feature must not change, meaning that subsequent outputs
// must always define the same issuer identity (the identity does not need to be unlocked anymore though).
// must always define the same issuer address (the address does not need to be unlocked anymore though).
type IssuerFeature struct {
Address Address `serix:""`
}
Expand Down
2 changes: 1 addition & 1 deletion feat_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// SenderFeature is a feature which associates an output
// with a sender identity. The sender identity needs to be unlocked in the transaction
// with a sender address. The sender address needs to be unlocked in the transaction
// for the SenderFeature to be valid.
type SenderFeature struct {
Address Address `serix:""`
Expand Down
6 changes: 3 additions & 3 deletions gen/unlock_ref.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/iotaledger/hive.go/serializer/v2"
)

// {{.Name}} is an Unlock which references a previous unlock.
// {{.Name}} is an Unlock which references a previous input/unlock.
type {{.Name}} struct {
// The other unlock this {{.Name}} references to.
// The other input/unlock this {{.Name}} references to.
Reference uint16 `serix:""`
}

Expand All @@ -26,7 +26,7 @@ func ({{.Receiver}} *{{.Name}}) Chainable() bool {
{{if index .Features "chainable"}} return true {{else}} return false {{end}}
}

func ({{.Receiver}} *{{.Name}}) Ref() uint16 {
func ({{.Receiver}} *{{.Name}}) ReferencedInputIndex() uint16 {
return {{.Receiver}}.Reference
}

Expand Down
9 changes: 5 additions & 4 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ type Input interface {
Type() InputType
}

// InputsSyntacticalUnique returns an ElementValidationFunc which checks that every input has a unique UTXO ref.
// InputsSyntacticalUnique returns an ElementValidationFunc which checks that every input has a unique reference UTXO index.
func InputsSyntacticalUnique() ElementValidationFunc[Input] {
utxoSet := map[string]int{}

return func(index int, input Input) error {
switch castInput := input.(type) {
case *UTXOInput:
utxoRef := castInput.OutputID()
k := string(utxoRef[:])
referencedOutputID := castInput.OutputID()
k := string(referencedOutputID[:])
if j, has := utxoSet[k]; has {
return ierrors.Wrapf(ErrInputUTXORefsNotUnique, "input %d and %d share the same UTXO ref", j, index)
return ierrors.Wrapf(ErrInputUTXORefsNotUnique, "input %d and %d share the same referenced UTXO index", j, index)
}
utxoSet[k] = index
default:
Expand All @@ -106,6 +106,7 @@ func InputsSyntacticalIndicesWithinBounds() ElementValidationFunc[Input] {
return func(index int, input Input) error {
switch castInput := input.(type) {
case *UTXOInput:
// TODO: do we really want to check the max value on the input side?
if castInput.Index() < RefUTXOIndexMin || castInput.Index() > RefUTXOIndexMax {
return ierrors.Wrapf(ErrRefUTXOIndexInvalid, "input %d", index)
}
Expand Down
2 changes: 1 addition & 1 deletion input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestInputsSyntacticalIndicesWithinBounds(t *testing.T) {
wantErr: nil,
},
{
name: "fail - invalid UTXO ref index",
name: "fail - invalid reference UTXO index",
inputs: iotago.Inputs[iotago.Input]{
&iotago.UTXOInput{
TransactionID: [36]byte{},
Expand Down
60 changes: 30 additions & 30 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ var outputNames = [OutputDelegation + 1]string{
}

var (
// ErrTransDepIdentOutputNonUTXOChainID gets returned when a TransDepIdentOutput has a ChainID which is not a UTXOIDChainID.
ErrTransDepIdentOutputNonUTXOChainID = ierrors.New("transition dependable ident outputs must have UTXO chain IDs")
// ErrTransDepIdentOutputNextInvalid gets returned when a TransDepIdentOutput's next state is invalid.
ErrTransDepIdentOutputNextInvalid = ierrors.New("transition dependable ident output's next output is invalid")
// ErrOwnerTransitionDependentOutputNonUTXOChainID gets returned when a OwnerTransitionDependentOutput has a ChainID which is not a UTXOIDChainID.
ErrOwnerTransitionDependentOutputNonUTXOChainID = ierrors.New("owner transition dependent outputs must have UTXO chain IDs")
// ErrOwnerTransitionDependentOutputNextInvalid gets returned when a OwnerTransitionDependentOutput's next state is invalid.
ErrOwnerTransitionDependentOutputNextInvalid = ierrors.New("owner transition dependent output's next output is invalid")
// ErrArrayValidationOrderViolatesLexicalOrder gets returned if the array elements are not in lexical order.
ErrArrayValidationOrderViolatesLexicalOrder = ierrors.New("array elements must be in their lexical order")
// ErrArrayValidationViolatesUniqueness gets returned if the array elements are not unique.
Expand Down Expand Up @@ -277,24 +277,24 @@ func (outputs Outputs[T]) NativeTokenSum() (NativeTokenSum, error) {
}

// This is a helper function to check if an output is unlockable by a given target.
func outputUnlockableBy(output Output, next TransDepIdentOutput, target Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) (bool, error) {
func outputUnlockableBy(output Output, next OwnerTransitionDependentOutput, target Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) (bool, error) {
unlockConds := output.UnlockConditionSet()
var ownerIdent Address
var owner Address
switch x := output.(type) {
case TransIndepIdentOutput:
ownerIdent = x.Ident()
case TransDepIdentOutput:
targetToUnlock, err := x.Ident(next)
case OwnerTransitionIndependentOutput:
owner = x.Owner()
case OwnerTransitionDependentOutput:
targetToUnlock, err := x.Owner(next)
if err != nil {
return false, err
}
ownerIdent = targetToUnlock
owner = targetToUnlock
default:
panic("invalid output type in outputUnlockableBy")
}

targetIdentCanUnlock := unlockConds.unlockableBy(target, ownerIdent, pastBoundedSlotIndex, futureBoundedSlotIndex)
if !targetIdentCanUnlock {
targetAddrCanUnlock := unlockConds.unlockableBy(target, owner, pastBoundedSlotIndex, futureBoundedSlotIndex)
if !targetAddrCanUnlock {
return false, nil
}

Expand All @@ -320,30 +320,30 @@ func PotentialMana(manaDecayProvider *ManaDecayProvider, storageScoreStructure *
return manaDecayProvider.GenerateManaAndDecayBySlots(excessBaseTokens, creationSlot, targetSlot)
}

// TransIndepIdentOutput is a type of Output where the identity to unlock is independent
// OwnerTransitionIndependentOutput is a type of Output where the address to unlock is independent
// of any transition the output does (without considering Feature(s)).
type TransIndepIdentOutput interface {
type OwnerTransitionIndependentOutput interface {
Output
// Ident returns the default identity to which this output is locked to.
Ident() Address
// UnlockableBy tells whether the given ident can unlock this Output
// Owner returns the default address to which this output is locked to.
Owner() Address
// UnlockableBy tells whether the given address can unlock this Output
// while also taking into consideration constraints enforced by UnlockConditions(s) within this Output (if any).
UnlockableBy(ident Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool
UnlockableBy(addr Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool
}

// TransDepIdentOutput is a type of Output where the identity to unlock is dependent
// OwnerTransitionDependentOutput is a type of Output where the address to unlock is dependent
// on the transition the output does (without considering UnlockConditions(s)).
type TransDepIdentOutput interface {
type OwnerTransitionDependentOutput interface {
ChainOutput
// Ident computes the identity to which this output is locked to by examining
// the transition to the next output state. If next is nil, then this TransDepIdentOutput
// treats the ident computation as being for ChainTransitionTypeDestroy.
Ident(next TransDepIdentOutput) (Address, error)
// UnlockableBy tells whether the given ident can unlock this Output
// Owner computes the address to which this output is locked to by examining
// the transition to the next output state. If next is nil, then this OwnerTransitionDependentOutput
// treats the owner computation as being for ChainTransitionTypeDestroy.
Owner(next OwnerTransitionDependentOutput) (Address, error)
// UnlockableBy tells whether the given address can unlock this Output
// while also taking into consideration constraints enforced by UnlockConditions(s) within this Output
// and the next state of this TransDepIdentOutput. To indicate that this TransDepIdentOutput
// and the next state of this OwnerTransitionDependentOutput. To indicate that this OwnerTransitionDependentOutput
// is to be destroyed, pass nil as next.
UnlockableBy(ident Address, next TransDepIdentOutput, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) (bool, error)
UnlockableBy(addr Address, next OwnerTransitionDependentOutput, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) (bool, error)
}

// OutputsSyntacticalDepositAmount returns an ElementValidationFunc[Output] which checks that:
Expand Down Expand Up @@ -472,7 +472,7 @@ func OutputsSyntacticalAccount() ElementValidationFunc[Output] {
}
}

if addr, ok := accountOutput.Ident().(*AccountAddress); ok && AccountAddress(accountOutput.AccountID) == *addr {
if addr, ok := accountOutput.Owner().(*AccountAddress); ok && AccountAddress(accountOutput.AccountID) == *addr {
return ierrors.WithMessagef(ErrAccountOutputCyclicAddress, "output %d", index)
}

Expand Down Expand Up @@ -564,7 +564,7 @@ func OutputsSyntacticalNFT() ElementValidationFunc[Output] {
return nil
}

if addr, ok := nftOutput.Ident().(*NFTAddress); ok && NFTAddress(nftOutput.NFTID) == *addr {
if addr, ok := nftOutput.Owner().(*NFTAddress); ok && NFTAddress(nftOutput.NFTID) == *addr {
return ierrors.WithMessagef(ErrNFTOutputCyclicAddress, "output %d", index)
}

Expand Down
6 changes: 3 additions & 3 deletions output_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (a *AccountOutput) Equal(other Output) bool {
return true
}

func (a *AccountOutput) UnlockableBy(ident Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(a, nil, ident, pastBoundedSlotIndex, futureBoundedSlotIndex)
func (a *AccountOutput) UnlockableBy(addr Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(a, nil, addr, pastBoundedSlotIndex, futureBoundedSlotIndex)
return ok
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func (a *AccountOutput) WorkScore(workScoreParameters *WorkScoreParameters) (Wor
return workScoreParameters.Output.Add(workScoreConditions, workScoreFeatures, workScoreImmutableFeatures)
}

func (a *AccountOutput) Ident() Address {
func (a *AccountOutput) Owner() Address {
return a.UnlockConditions.MustSet().Address().Address
}

Expand Down
10 changes: 5 additions & 5 deletions output_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (a *AnchorOutput) Equal(other Output) bool {
return true
}

func (a *AnchorOutput) UnlockableBy(ident Address, next TransDepIdentOutput, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) (bool, error) {
return outputUnlockableBy(a, next, ident, pastBoundedSlotIndex, futureBoundedSlotIndex)
func (a *AnchorOutput) UnlockableBy(addr Address, next OwnerTransitionDependentOutput, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) (bool, error) {
return outputUnlockableBy(a, next, addr, pastBoundedSlotIndex, futureBoundedSlotIndex)
}

func (a *AnchorOutput) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
Expand Down Expand Up @@ -129,22 +129,22 @@ func (a *AnchorOutput) WorkScore(workScoreParameters *WorkScoreParameters) (Work
return workScoreParameters.Output.Add(workScoreConditions, workScoreFeatures, workScoreImmutableFeatures)
}

func (a *AnchorOutput) Ident(nextState TransDepIdentOutput) (Address, error) {
func (a *AnchorOutput) Owner(nextState OwnerTransitionDependentOutput) (Address, error) {
// if there isn't a next state, then only the governance address can destroy the anchor
if nextState == nil {
return a.GovernorAddress(), nil
}
otherAnchorOutput, isAnchorOutput := nextState.(*AnchorOutput)
if !isAnchorOutput {
return nil, ierrors.Wrapf(ErrTransDepIdentOutputNextInvalid, "expected AnchorOutput but got %s for ident computation", nextState.Type())
return nil, ierrors.Wrapf(ErrOwnerTransitionDependentOutputNextInvalid, "expected AnchorOutput but got %s for owner computation", nextState.Type())
}
switch {
case a.StateIndex == otherAnchorOutput.StateIndex:
return a.GovernorAddress(), nil
case a.StateIndex+1 == otherAnchorOutput.StateIndex:
return a.StateController(), nil
default:
return nil, ierrors.Wrap(ErrTransDepIdentOutputNextInvalid, "can not compute right ident for anchor output as state index delta is invalid")
return nil, ierrors.Wrap(ErrOwnerTransitionDependentOutputNextInvalid, "can not compute right owner for anchor output as state index delta is invalid")
}
}

Expand Down
6 changes: 3 additions & 3 deletions output_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (e *BasicOutput) Equal(other Output) bool {
return true
}

func (e *BasicOutput) UnlockableBy(ident Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(e, nil, ident, pastBoundedSlotIndex, futureBoundedSlotIndex)
func (e *BasicOutput) UnlockableBy(addr Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(e, nil, addr, pastBoundedSlotIndex, futureBoundedSlotIndex)
return ok
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func (e *BasicOutput) StoredMana() Mana {
return e.Mana
}

func (e *BasicOutput) Ident() Address {
func (e *BasicOutput) Owner() Address {
return e.UnlockConditions.MustSet().Address().Address
}

Expand Down
6 changes: 3 additions & 3 deletions output_delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ func (d *DelegationOutput) Equal(other Output) bool {
return true
}

func (d *DelegationOutput) Ident() Address {
func (d *DelegationOutput) Owner() Address {
return d.UnlockConditions.MustSet().Address().Address
}

func (d *DelegationOutput) UnlockableBy(ident Address, pastBoundedSlot SlotIndex, futureBoundedSlot SlotIndex) bool {
ok, _ := outputUnlockableBy(d, nil, ident, pastBoundedSlot, futureBoundedSlot)
func (d *DelegationOutput) UnlockableBy(addr Address, pastBoundedSlot SlotIndex, futureBoundedSlot SlotIndex) bool {
ok, _ := outputUnlockableBy(d, nil, addr, pastBoundedSlot, futureBoundedSlot)
return ok
}

Expand Down
8 changes: 4 additions & 4 deletions output_foundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ func (f *FoundryOutput) Equal(other Output) bool {
return true
}

func (f *FoundryOutput) Ident() Address {
func (f *FoundryOutput) Owner() Address {
return f.UnlockConditionSet().ImmutableAccount().Address
}

func (f *FoundryOutput) UnlockableBy(ident Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(f, nil, ident, pastBoundedSlotIndex, futureBoundedSlotIndex)
func (f *FoundryOutput) UnlockableBy(addr Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(f, nil, addr, pastBoundedSlotIndex, futureBoundedSlotIndex)
return ok
}

Expand Down Expand Up @@ -225,7 +225,7 @@ func (f *FoundryOutput) ChainID() ChainID {

// FoundryID returns the FoundryID of this FoundryOutput.
func (f *FoundryOutput) FoundryID() (FoundryID, error) {
return FoundryIDFromAddressAndSerialNumberAndTokenScheme(f.Ident(), f.SerialNumber, f.TokenScheme.Type())
return FoundryIDFromAddressAndSerialNumberAndTokenScheme(f.Owner(), f.SerialNumber, f.TokenScheme.Type())
}

// MustFoundryID works like FoundryID but panics if an error occurs.
Expand Down
10 changes: 5 additions & 5 deletions output_id_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type outputIDProofTest struct {
}

func TestOutputIDProof(t *testing.T) {
ident1 := tpkg.RandEd25519Address()
addr1 := tpkg.RandEd25519Address()

inputIDs := tpkg.RandOutputIDs(1)

Expand All @@ -36,7 +36,7 @@ func TestOutputIDProof(t *testing.T) {
return &iotago.BasicOutput{
Amount: OneIOTA,
UnlockConditions: iotago.BasicOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: ident1},
&iotago.AddressUnlockCondition{Address: addr1},
},
}
}),
Expand All @@ -56,7 +56,7 @@ func TestOutputIDProof(t *testing.T) {
return &iotago.BasicOutput{
Amount: OneIOTA,
UnlockConditions: iotago.BasicOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: ident1},
&iotago.AddressUnlockCondition{Address: addr1},
},
}
}),
Expand All @@ -76,7 +76,7 @@ func TestOutputIDProof(t *testing.T) {
return &iotago.BasicOutput{
Amount: OneIOTA,
UnlockConditions: iotago.BasicOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: ident1},
&iotago.AddressUnlockCondition{Address: addr1},
},
}
}),
Expand All @@ -96,7 +96,7 @@ func TestOutputIDProof(t *testing.T) {
return &iotago.BasicOutput{
Amount: OneIOTA,
UnlockConditions: iotago.BasicOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: ident1},
&iotago.AddressUnlockCondition{Address: addr1},
},
}
}),
Expand Down
Loading

0 comments on commit 7aa8e85

Please sign in to comment.