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

events: Adjust CustomMetadata for Orml events #354

Merged
merged 1 commit into from
Jun 26, 2023
Merged
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
74 changes: 70 additions & 4 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package types

import (
"errors"
"fmt"

"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
Expand Down Expand Up @@ -294,10 +295,75 @@ type AssetMetadata struct {
}

type CustomMetadata struct {
Xcm XcmMetadata
Mintable bool
Permissioned bool
PoolCurrency bool
Transferability CrossChainTransferability
Mintable bool
Permissioned bool
PoolCurrency bool
}

type CrossChainTransferability struct {
IsNone bool

IsXcm bool
AsXcm XcmMetadata

IsConnectors bool

IsAll bool
AsAll XcmMetadata
}

func (c *CrossChainTransferability) Decode(decoder scale.Decoder) error {
b, err := decoder.ReadOneByte()

if err != nil {
return err
}

switch b {
case 0:
c.IsNone = true

return nil
case 1:
c.IsXcm = true

return decoder.Decode(&c.AsXcm)
case 2:
c.IsConnectors = true

return nil

case 3:
c.IsAll = true

return decoder.Decode(&c.AsAll)
default:
return errors.New("unsupported cross chain transferability")
}
}

func (c CrossChainTransferability) Encode(encoder scale.Encoder) error {
switch {
case c.IsNone:
return encoder.PushByte(0)
case c.IsXcm:
if err := encoder.PushByte(1); err != nil {
return err
}

return encoder.Encode(c.AsXcm)
case c.IsConnectors:
return encoder.PushByte(2)
case c.IsAll:
if err := encoder.PushByte(3); err != nil {
return err
}

return encoder.Encode(c.AsAll)
default:
return errors.New("unsupported cross chain transferability")
}
}

type XcmMetadata struct {
Expand Down