From 2c6e55b5c363bfdbb10d230b3dac15223e886d92 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:01:43 +0200 Subject: [PATCH] Update event types (#349) * event: Update treasury events * types: Add Orml Asset Registry events * types: Update CurrencyID --- types/event_record.go | 19 +++++---- types/events.go | 51 ++++++++++++++++++++++++ types/sale.go | 92 ++++++++++++++++++++++++++++++++----------- 3 files changed, 132 insertions(+), 30 deletions(-) diff --git a/types/event_record.go b/types/event_record.go index 0f19ae5a2..49fb2cc9b 100644 --- a/types/event_record.go +++ b/types/event_record.go @@ -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"` @@ -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"` diff --git a/types/events.go b/types/events.go index 88d43d5d8..6ca8e257d 100644 --- a/types/events.go +++ b/types/events.go @@ -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 @@ -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 diff --git a/types/sale.go b/types/sale.go index 0cfc0def8..81ba34755 100644 --- a/types/sale.go +++ b/types/sale.go @@ -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 @@ -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 { @@ -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 {