Skip to content

Commit

Permalink
Update event types (#349)
Browse files Browse the repository at this point in the history
* event: Update treasury events

* types: Add Orml Asset Registry events

* types: Update CurrencyID
  • Loading branch information
cdamian authored Jun 9, 2023
1 parent a8abd09 commit 2c6e55b
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 30 deletions.
19 changes: 12 additions & 7 deletions types/event_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ type EventRecords struct {

Offences_Offence []EventOffencesOffence `test-gen-blockchain:"polkadot"`

OrmlAssetRegistry_RegisteredAsset []EventOrmlAssetRegistryRegisteredAsset `test-gen-blockchain:"polkadot"`
OrmlAssetRegistry_UpdatedAsset []EventOrmlAssetRegistryUpdatedAsset `test-gen-blockchain:"polkadot"`

Paras_CurrentCodeUpdated []EventParasCurrentCodeUpdated `test-gen-blockchain:"polkadot"`
Paras_CurrentHeadUpdated []EventParasCurrentHeadUpdated `test-gen-blockchain:"polkadot"`
Paras_CodeUpgradeScheduled []EventParasCodeUpgradeScheduled `test-gen-blockchain:"polkadot"`
Expand Down Expand Up @@ -380,13 +383,15 @@ type EventRecords struct {

TransactionPayment_TransactionFeePaid []EventTransactionPaymentTransactionFeePaid `test-gen-blockchain:"westend"`

Treasury_Awarded []EventTreasuryAwarded `test-gen-blockchain:"altair"`
Treasury_Burnt []EventTreasuryBurnt `test-gen-blockchain:"altair"`
Treasury_Deposit []EventTreasuryDeposit `test-gen-blockchain:"altair"`
Treasury_Proposed []EventTreasuryProposed `test-gen-blockchain:"altair"`
Treasury_Rejected []EventTreasuryRejected `test-gen-blockchain:"altair"`
Treasury_Rollover []EventTreasuryRollover `test-gen-blockchain:"altair"`
Treasury_Spending []EventTreasurySpending `test-gen-blockchain:"altair"`
Treasury_Proposed []EventTreasuryProposed `test-gen-blockchain:"altair"`
Treasury_Spending []EventTreasurySpending `test-gen-blockchain:"altair"`
Treasury_Awarded []EventTreasuryAwarded `test-gen-blockchain:"altair"`
Treasury_Rejected []EventTreasuryRejected `test-gen-blockchain:"altair"`
Treasury_Burnt []EventTreasuryBurnt `test-gen-blockchain:"altair"`
Treasury_Rollover []EventTreasuryRollover `test-gen-blockchain:"altair"`
Treasury_Deposit []EventTreasuryDeposit `test-gen-blockchain:"altair"`
Treasury_SpendApproved []EventTreasurySpendApproved `test-gen-blockchain:"altair"`
Treasury_UpdatedInactive []EventTreasuryUpdatedInactive `test-gen-blockchain:"altair"`

Uniques_ApprovalCancelled []EventUniquesApprovalCancelled `test-gen-blockchain:"altair"`
Uniques_ApprovedTransfer []EventUniquesApprovedTransfer `test-gen-blockchain:"altair"`
Expand Down
51 changes: 51 additions & 0 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,40 @@ type EventOffencesOffence struct {
Topics []Hash
}

type EventOrmlAssetRegistryRegisteredAsset struct {
Phase Phase
AssetID CurrencyID
Metadata AssetMetadata
Topics []Hash
}

type EventOrmlAssetRegistryUpdatedAsset struct {
Phase Phase
AssetID CurrencyID
Metadata AssetMetadata
Topics []Hash
}

type AssetMetadata struct {
Decimals U32
Name []U8
Symbol []U8
ExistentialBalance U128
Location Option[VersionedMultiLocation]
Additional CustomMetadata
}

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

type XcmMetadata struct {
FeePerSecond Option[U128]
}

// EventParasCurrentCodeUpdated is emitted when the current code has been updated for a Para.
type EventParasCurrentCodeUpdated struct {
Phase Phase
Expand Down Expand Up @@ -2516,6 +2550,23 @@ type EventTreasuryDeposit struct {
Topics []Hash
}

// EventTreasurySpendApproved is emitted when a spend is approved.
type EventTreasurySpendApproved struct {
Phase Phase
ProposalIndex U32
Amount U128
Beneficiary AccountID
Topics []Hash
}

// EventTreasuryUpdatedInactive is emitted when the inactive funds of the pallet have been updated.
type EventTreasuryUpdatedInactive struct {
Phase Phase
Reactivated U128
Deactivated U128
Topics []Hash
}

// EventTipsNewTip is emitted when a new tip suggestion has been opened.
type EventTipsNewTip struct {
Phase Phase
Expand Down
92 changes: 69 additions & 23 deletions types/sale.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

package types

import "github.com/centrifuge/go-substrate-rpc-client/v4/scale"
import (
"errors"

"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
)

type Tranche struct {
FirstVal U64
Expand Down Expand Up @@ -51,20 +55,50 @@ func (p *PermissionedCurrency) Encode(_ scale.Encoder) error {
return nil
}

type StakingCurrency struct {
IsBlockRewards bool
}

func (s *StakingCurrency) Decode(decoder scale.Decoder) error {
b, err := decoder.ReadOneByte()
if err != nil {
return err
}

switch b {
case 0:
s.IsBlockRewards = true

return nil
default:
return errors.New("unsupported staking currency")
}
}

func (s StakingCurrency) Encode(encoder scale.Encoder) error {
switch {
case s.IsBlockRewards:
return encoder.PushByte(0)
default:
return errors.New("unsupported staking currency")
}
}

type CurrencyID struct {
IsNative bool

IsUsd bool

IsTranche bool
Tranche Tranche

IsKSM bool

IsKUSD bool
IsAUSD bool

IsForeignAsset bool
AsForeignAsset U32

IsPermissioned bool
PermissionedCurrency PermissionedCurrency
IsStaking bool
AsStaking StakingCurrency
}

func (c *CurrencyID) Decode(decoder scale.Decoder) error {
Expand All @@ -76,50 +110,62 @@ func (c *CurrencyID) Decode(decoder scale.Decoder) error {
switch b {
case 0:
c.IsNative = true

return nil
case 1:
c.IsUsd = true
case 2:
c.IsTranche = true

return decoder.Decode(&c.Tranche)
case 3:
case 2:
c.IsKSM = true

return nil
case 3:
c.IsAUSD = true

return nil
case 4:
c.IsKUSD = true
c.IsForeignAsset = true

return decoder.Decode(&c.AsForeignAsset)
case 5:
c.IsPermissioned = true
c.IsStaking = true

return decoder.Decode(&c.PermissionedCurrency)
return decoder.Decode(&c.AsStaking)
default:
return errors.New("unsupported currency ID")
}

return nil
}

func (c CurrencyID) Encode(encoder scale.Encoder) error {
switch {
case c.IsNative:
return encoder.PushByte(0)
case c.IsUsd:
return encoder.PushByte(1)
case c.IsTranche:
if err := encoder.PushByte(2); err != nil {
if err := encoder.PushByte(1); err != nil {
return err
}

return encoder.Encode(c.Tranche)
case c.IsKSM:
return encoder.PushByte(2)
case c.IsAUSD:
return encoder.PushByte(3)
case c.IsKUSD:
return encoder.PushByte(4)
case c.IsPermissioned:
case c.IsForeignAsset:
if err := encoder.PushByte(4); err != nil {
return err
}

return encoder.Encode(c.AsForeignAsset)
case c.IsStaking:
if err := encoder.PushByte(5); err != nil {
return err
}

return encoder.Encode(c.PermissionedCurrency)
return encoder.Encode(c.AsStaking)
default:
return errors.New("unsupported currency ID")
}

return nil
}

type Price struct {
Expand Down

0 comments on commit 2c6e55b

Please sign in to comment.