Skip to content

Commit

Permalink
add CompactStatement varying datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
axaysagathiya committed Dec 19, 2024
1 parent 3f81dd2 commit 3156a15
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions dot/parachain/types/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,67 @@ type SignedFullStatementWithPVD struct {
// otherwise, it should be nil.
PersistedValidationData *PersistedValidationData
}

type SecondedCandidateHash CandidateHash

type CompactStatementValues interface {
Valid | SecondedCandidateHash
}

// Statements that can be made about parachain candidates.
// These are the actual values that are signed.
type CompactStatement struct {
inner any
}

func setCompactStatement[Value CompactStatementValues](mvdt *CompactStatement, value Value) {
mvdt.inner = value
}

func (mvdt *CompactStatement) SetValue(value any) (err error) {
switch value := value.(type) {
case Valid:
setCompactStatement(mvdt, value)
return
case SecondedCandidateHash:
setCompactStatement(mvdt, value)
return
default:
return fmt.Errorf("unsupported type")
}
}

func (mvdt CompactStatement) IndexValue() (index uint, value any, err error) {
switch mvdt.inner.(type) {
case Valid:
return 2, mvdt.inner, nil
case SecondedCandidateHash:
return 1, mvdt.inner, nil
}
return 0, nil, scale.ErrUnsupportedVaryingDataTypeValue
}

func (mvdt CompactStatement) Value() (value any, err error) {
_, value, err = mvdt.IndexValue()
return
}

func (mvdt CompactStatement) ValueAt(index uint) (value any, err error) {
switch index {
case 2:
return Valid{}, nil
case 1:
return SecondedCandidateHash{}, nil
}
return nil, scale.ErrUnknownVaryingDataTypeValue
}

func (c *CompactStatement) Encode() ([]byte, error) {
// TODO: implement this
return nil, nil
}

func (c *CompactStatement) Decode(in []byte) error {
// TODO: implement this
return nil
}

0 comments on commit 3156a15

Please sign in to comment.