Skip to content

Commit

Permalink
Expose some helper functions (#420)
Browse files Browse the repository at this point in the history
* Export SignatureFromJSONRawMsg

* Expose Address and Signature read and write guards
  • Loading branch information
muXxer authored Mar 20, 2023
1 parent 4f1f458 commit d533cb3
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
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

0 comments on commit d533cb3

Please sign in to comment.