Skip to content

Commit

Permalink
events: Adjust CustomMetadata for Orml events (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian authored Jun 26, 2023
1 parent 2c6e55b commit fa39166
Showing 1 changed file with 70 additions and 4 deletions.
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

0 comments on commit fa39166

Please sign in to comment.