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

Expose some helper functions #420

Merged
merged 2 commits into from
Mar 20, 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
4 changes: 2 additions & 2 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func jsonAddressToAddress(jAddr JSONSerializable) (Address, error) {
}

// checks whether the given Serializable is an Address and also supported AddressType.
func addrWriteGuard(supportedAddr AddressTypeSet) serializer.SerializableWriteGuardFunc {
func AddressWriteGuard(supportedAddr AddressTypeSet) serializer.SerializableWriteGuardFunc {
return func(seri serializer.Serializable) error {
if seri == nil {
return fmt.Errorf("%w: because nil", ErrTypeIsNotSupportedAddress)
Expand All @@ -159,7 +159,7 @@ func addrWriteGuard(supportedAddr AddressTypeSet) serializer.SerializableWriteGu
}
}

func addrReadGuard(supportedAddr AddressTypeSet) serializer.SerializableReadGuardFunc {
func AddressReadGuard(supportedAddr AddressTypeSet) serializer.SerializableReadGuardFunc {
return func(ty uint32) (serializer.Serializable, error) {
if _, supported := supportedAddr[AddressType(ty)]; !supported {
return nil, fmt.Errorf("%w: because not in set %v (%d)", ErrTypeIsNotSupportedAddress, supportedAddr, ty)
Expand Down
4 changes: 2 additions & 2 deletions feat_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
issuerFeatAddrGuard = serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
4 changes: 2 additions & 2 deletions feat_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
senderFeatAddrGuard = serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
4 changes: 2 additions & 2 deletions migrated_funds_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

var (
migratedFundEntryFeatBlockAddrGuard = serializer.SerializableGuard{
ReadGuard: addrReadGuard(AddressTypeSet{AddressEd25519: struct{}{}}),
WriteGuard: addrWriteGuard(AddressTypeSet{AddressEd25519: struct{}{}}),
ReadGuard: AddressReadGuard(AddressTypeSet{AddressEd25519: struct{}{}}),
WriteGuard: AddressWriteGuard(AddressTypeSet{AddressEd25519: struct{}{}}),
}
)

Expand Down
4 changes: 2 additions & 2 deletions milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ var (
Min: MinSignaturesInAMilestone,
Max: MaxSignaturesInAMilestone,
Guards: serializer.SerializableGuard{
ReadGuard: sigReadGuard(milestoneSupportedSigTypes),
WriteGuard: sigWriteGuard(milestoneSupportedSigTypes),
ReadGuard: SignatureReadGuard(milestoneSupportedSigTypes),
WriteGuard: SignatureWriteGuard(milestoneSupportedSigTypes),
},
UniquenessSliceFunc: func(next []byte) []byte { return next[:ed25519.PublicKeySize] },
ValidationMode: serializer.ArrayValidationModeNoDuplicates | serializer.ArrayValidationModeLexicalOrdering,
Expand Down
6 changes: 3 additions & 3 deletions signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type Signature interface {
type SignatureTypeSet map[SignatureType]struct{}

// checks whether the given Serializable is a Signature and also supported SignatureType.
func sigWriteGuard(supportedSigs SignatureTypeSet) serializer.SerializableWriteGuardFunc {
func SignatureWriteGuard(supportedSigs SignatureTypeSet) serializer.SerializableWriteGuardFunc {
return func(seri serializer.Serializable) error {
if seri == nil {
return fmt.Errorf("%w: because nil", ErrTypeIsNotSupportedSignature)
Expand All @@ -111,7 +111,7 @@ func sigWriteGuard(supportedSigs SignatureTypeSet) serializer.SerializableWriteG
}
}

func sigReadGuard(supportedSigs SignatureTypeSet) serializer.SerializableReadGuardFunc {
func SignatureReadGuard(supportedSigs SignatureTypeSet) serializer.SerializableReadGuardFunc {
return func(ty uint32) (serializer.Serializable, error) {
if _, supported := supportedSigs[SignatureType(ty)]; !supported {
return nil, fmt.Errorf("%w: because not in set %v (%d)", ErrTypeIsNotSupportedSignature, supportedSigs, ty)
Expand All @@ -132,7 +132,7 @@ func SignatureSelector(sigType uint32) (Signature, error) {
return seri, nil
}

func signatureFromJSONRawMsg(jRawMsg *json.RawMessage) (Signature, error) {
func SignatureFromJSONRawMsg(jRawMsg *json.RawMessage) (Signature, error) {
jsonSignature, err := DeserializeObjectFromJSON(jRawMsg, jsonSignatureSelector)
if err != nil {
return nil, fmt.Errorf("can't decode signature type from JSON: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
addrUnlockCondAddrGuard = &serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
expUnlockCondAddrGuard = &serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
govAddrUnlockCondAddrGuard = &serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_imm_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
immAliasUnlockCondAddrGuard = &serializer.SerializableGuard{
ReadGuard: addrReadGuard(AddressTypeSet{AddressAlias: struct{}{}}),
WriteGuard: addrWriteGuard(AddressTypeSet{AddressAlias: struct{}{}}),
ReadGuard: AddressReadGuard(AddressTypeSet{AddressAlias: struct{}{}}),
WriteGuard: AddressWriteGuard(AddressTypeSet{AddressAlias: struct{}{}}),
}
)

Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_state_ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
stateCtrlUnlockCondAddrGuard = &serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_storage_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

var (
storageDepReturnUnlockCondAddrGuard = &serializer.SerializableGuard{
ReadGuard: addrReadGuard(allAddressTypeSet),
WriteGuard: addrWriteGuard(allAddressTypeSet),
ReadGuard: AddressReadGuard(allAddressTypeSet),
WriteGuard: AddressWriteGuard(allAddressTypeSet),
}
)

Expand Down
2 changes: 1 addition & 1 deletion unlock_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type jsonSignatureUnlock struct {
}

func (j *jsonSignatureUnlock) ToSerializable() (serializer.Serializable, error) {
sig, err := signatureFromJSONRawMsg(j.Signature)
sig, err := SignatureFromJSONRawMsg(j.Signature)
if err != nil {
return nil, err
}
Expand Down