Skip to content

Commit

Permalink
Quebec protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
e-asphyx committed Sep 26, 2024
1 parent f8fe374 commit 87e2864
Show file tree
Hide file tree
Showing 37 changed files with 2,207 additions and 44 deletions.
5 changes: 5 additions & 0 deletions protocol/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ecadlabs/gotez/v2/protocol/proto_017_PtNairob"
"github.com/ecadlabs/gotez/v2/protocol/proto_018_Proxford"
"github.com/ecadlabs/gotez/v2/protocol/proto_019_PtParisB"
"github.com/ecadlabs/gotez/v2/protocol/proto_021_PsquebeC"
)

type BlockInfo interface {
Expand All @@ -31,6 +32,8 @@ type BlockHeaderInfo interface {

func NewBlockInfo(proto *tz.ProtocolHash) (BlockInfo, error) {
switch *proto {
case core.Proto021PsquebeC:
return new(proto_021_PsquebeC.BlockInfo), nil
case core.Proto019PtParisB, core.Proto020PsParisC:
return new(proto_019_PtParisB.BlockInfo), nil
case core.Proto018Proxford:
Expand All @@ -54,6 +57,8 @@ func NewBlockInfo(proto *tz.ProtocolHash) (BlockInfo, error) {

func NewBlockHeaderInfo(proto *tz.ProtocolHash) (BlockHeaderInfo, error) {
switch *proto {
case core.Proto021PsquebeC:
return new(proto_021_PsquebeC.BlockHeaderInfo), nil
case core.Proto019PtParisB, core.Proto020PsParisC:
return new(proto_019_PtParisB.BlockHeaderInfo), nil
case core.Proto018Proxford:
Expand Down
25 changes: 25 additions & 0 deletions protocol/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ type protoTestData struct {
}

var testData = []protoTestData{
{
proto: &core.Proto021PsquebeC,
blocks: []string{
"155262",
"155263",
"155264",
"155265",
"155266",
"155267",
"155268",
"155269",
"155270",
"155271",
"155272",
"155273",
"155274",
"155275",
"155276",
"155277",
"155278",
"155279",
"155280",
"155281",
},
},
{
proto: &core.Proto019PtParisB,
blocks: []string{
Expand Down
3 changes: 3 additions & 0 deletions protocol/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import (
"github.com/ecadlabs/gotez/v2/protocol/proto_017_PtNairob"
"github.com/ecadlabs/gotez/v2/protocol/proto_018_Proxford"
"github.com/ecadlabs/gotez/v2/protocol/proto_019_PtParisB"
"github.com/ecadlabs/gotez/v2/protocol/proto_021_PsquebeC"
)

func NewConstants(proto *tz.ProtocolHash) (constants core.Constants, err error) {
switch *proto {
case core.Proto021PsquebeC:
constants = new(proto_021_PsquebeC.Constants)
case core.Proto019PtParisB, core.Proto020PsParisC:
constants = new(proto_019_PtParisB.Constants)
case core.Proto018Proxford:
Expand Down
40 changes: 0 additions & 40 deletions protocol/context.go

This file was deleted.

4 changes: 4 additions & 0 deletions protocol/core/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
Proto018Proxford = tz.ProtocolHash{0x0b, 0xf4, 0x4c, 0x7d, 0x64, 0xe3, 0xd7, 0xda, 0x27, 0xd9, 0x25, 0xd1, 0x0a, 0xf5, 0x35, 0xfb, 0x36, 0xce, 0xf0, 0xad, 0x41, 0x93, 0x0c, 0x79, 0x29, 0x77, 0x3f, 0x47, 0x31, 0xeb, 0xa1, 0x37}
Proto019PtParisB = tz.ProtocolHash{0xdb, 0xff, 0x65, 0x86, 0xa0, 0x48, 0x02, 0xd3, 0xf5, 0x13, 0xc6, 0x5a, 0x44, 0x4d, 0x9d, 0x4d, 0xeb, 0xe4, 0x2b, 0x17, 0xe9, 0xe7, 0x27, 0x3f, 0x8f, 0x6c, 0x11, 0x8e, 0xa3, 0xf4, 0xe0, 0x6e}
Proto020PsParisC = tz.ProtocolHash{0x58, 0x4d, 0x32, 0x39, 0x2e, 0xf2, 0x1a, 0x17, 0xef, 0x36, 0xdf, 0x07, 0x4f, 0x48, 0xaf, 0x06, 0x65, 0x3a, 0x8d, 0x31, 0x59, 0x57, 0xc9, 0x07, 0xd6, 0xa4, 0xc1, 0x8c, 0x3a, 0x00, 0xa5, 0xe1}
Proto021PsquebeC = tz.ProtocolHash{0x94, 0x12, 0xc8, 0x4f, 0xe6, 0x49, 0x2d, 0x94, 0x8e, 0x1b, 0xcf, 0x75, 0xa3, 0xc8, 0xf6, 0xcb, 0xc9, 0x0a, 0xf9, 0xaf, 0x42, 0x76, 0x5a, 0xe0, 0x03, 0x8c, 0x8b, 0x77, 0x81, 0x34, 0xfa, 0xb1}
)

var Protocols = []*tz.ProtocolHash{
Expand All @@ -50,6 +51,7 @@ var Protocols = []*tz.ProtocolHash{
&Proto018Proxford,
&Proto019PtParisB,
&Proto020PsParisC,
&Proto021PsquebeC,
}

var shortNames = map[tz.ProtocolHash]string{
Expand All @@ -74,6 +76,7 @@ var shortNames = map[tz.ProtocolHash]string{
Proto018Proxford: "018_Proxford",
Proto019PtParisB: "019_PtParisA",
Proto020PsParisC: "020_PsParisC",
Proto021PsquebeC: "021_PsquebeC",
}

var indices = map[tz.ProtocolHash]int{
Expand All @@ -98,6 +101,7 @@ var indices = map[tz.ProtocolHash]int{
Proto018Proxford: 18,
Proto019PtParisB: 19,
Proto020PsParisC: 20,
Proto021PsquebeC: 21,
}

func ProtocolShortName(proto *tz.ProtocolHash) string {
Expand Down
7 changes: 3 additions & 4 deletions protocol/latest/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package latest

import (
"github.com/ecadlabs/gotez/v2/protocol/core"
latest "github.com/ecadlabs/gotez/v2/protocol/proto_019_PtParisB"
latest "github.com/ecadlabs/gotez/v2/protocol/proto_021_PsquebeC"
)

var (
Expand Down Expand Up @@ -62,7 +62,6 @@ type EndorsementContentsAndResult = latest.AttestationContentsAndResult
type InlinedEndorsementContents = latest.InlinedAttestationContents
type InlinedAttestationContents = latest.InlinedAttestationContents
type DALAttestation = latest.DALAttestation
type DALAttestationContentsAndResult = latest.DALAttestationContentsAndResult
type Reveal = latest.Reveal
type RevealContentsAndResult = latest.RevealContentsAndResult
type Transaction = latest.Transaction
Expand Down Expand Up @@ -99,8 +98,8 @@ type SmartRollupExecuteOutboxMessage = latest.SmartRollupExecuteOutboxMessage
type SmartRollupExecuteOutboxMessageContentsAndResult = latest.SmartRollupExecuteOutboxMessageContentsAndResult
type SmartRollupRecoverBond = latest.SmartRollupRecoverBond
type SmartRollupRecoverBondContentsAndResult = latest.SmartRollupRecoverBondContentsAndResult
type DALPublishSlotHeader = latest.DALPublishSlotHeader
type DALPublishSlotHeaderContentsAndResult = latest.DALPublishSlotHeaderContentsAndResult
type DALPublishCommitment = latest.DALPublishCommitment
type DALPublishCommitmentContentsAndResult = latest.DALPublishCommitmentContentsAndResult
type ZkRollupOrigination = latest.ZkRollupOrigination
type ZkRollupOriginationContentsAndResult = latest.ZkRollupOriginationContentsAndResult
type ZkRollupPublish = latest.ZkRollupPublish
Expand Down
141 changes: 141 additions & 0 deletions protocol/proto_021_PsquebeC/balance_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package proto_021_PsquebeC

import (
tz "github.com/ecadlabs/gotez/v2"
"github.com/ecadlabs/gotez/v2/encoding"
"github.com/ecadlabs/gotez/v2/protocol/core"
"github.com/ecadlabs/gotez/v2/protocol/proto_012_Psithaca"
"github.com/ecadlabs/gotez/v2/protocol/proto_016_PtMumbai"
"github.com/ecadlabs/gotez/v2/protocol/proto_018_Proxford"
"github.com/ecadlabs/gotez/v2/protocol/proto_019_PtParisB"
)

type BalanceUpdates struct {
BalanceUpdates []*BalanceUpdate `tz:"dyn" json:"balance_updates"`
}

func (b *BalanceUpdates) GetBalanceUpdates() []core.BalanceUpdate {
out := make([]core.BalanceUpdate, len(b.BalanceUpdates))
for i, u := range b.BalanceUpdates {
out[i] = u
}
return out
}

type BalanceUpdate struct {
Contents BalanceUpdateContents `json:"contents"`
Change int64 `json:"change"`
Origin core.BalanceUpdateOrigin `json:"origin"`
}

func (b *BalanceUpdate) GetContents() core.BalanceUpdateContents { return b.Contents }
func (b *BalanceUpdate) GetChange() int64 { return b.Change }
func (b *BalanceUpdate) GetOrigin() core.BalanceUpdateOrigin { return b.Origin }

type BalanceUpdateContract = proto_012_Psithaca.BalanceUpdateContract
type BalanceUpdateCommitments = proto_012_Psithaca.BalanceUpdateCommitments
type BalanceUpdateBlockFees = proto_012_Psithaca.BalanceUpdateBlockFees
type BalanceUpdateNonceRevelationRewards = proto_012_Psithaca.BalanceUpdateNonceRevelationRewards
type BalanceUpdateBakingRewards = proto_012_Psithaca.BalanceUpdateBakingRewards
type BalanceUpdateBakingBonuses = proto_012_Psithaca.BalanceUpdateBakingBonuses
type BalanceUpdateStorageFees = proto_012_Psithaca.BalanceUpdateStorageFees
type BalanceUpdateDoubleSigningPunishments = proto_012_Psithaca.BalanceUpdateDoubleSigningPunishments
type BalanceUpdateLiquidityBakingSubsidies = proto_012_Psithaca.BalanceUpdateLiquidityBakingSubsidies
type BalanceUpdateBurned = proto_012_Psithaca.BalanceUpdateBurned
type BalanceUpdateBootstrap = proto_012_Psithaca.BalanceUpdateBootstrap
type BalanceUpdateInvoice = proto_012_Psithaca.BalanceUpdateInvoice
type BalanceUpdateInitialCommitments = proto_012_Psithaca.BalanceUpdateInitialCommitments
type BalanceUpdateMinted = proto_012_Psithaca.BalanceUpdateMinted
type BalanceUpdateSmartRollupRefutationPunishments = proto_016_PtMumbai.BalanceUpdateSmartRollupRefutationPunishments
type BalanceUpdateSmartRollupRefutationRewards = proto_016_PtMumbai.BalanceUpdateSmartRollupRefutationRewards
type StakingDelegatorNumerator = proto_018_Proxford.StakingDelegatorNumerator
type StakingDelegateDenominator = proto_018_Proxford.StakingDelegateDenominator
type BalanceUpdateUnstakedDeposits = proto_018_Proxford.BalanceUpdateUnstakedDeposits
type BalanceUpdateDeposits = proto_019_PtParisB.BalanceUpdateDeposits

//json:category=BalanceUpdateCategory(),kind=BalanceUpdateKind()
type BalanceUpdateAttestingRewards struct{}

func (BalanceUpdateAttestingRewards) BalanceUpdateCategory() string {
return "attesting_rewards"
}
func (BalanceUpdateAttestingRewards) BalanceUpdateKind() core.BalanceUpdateKind {
return core.BalanceUpdateKindMinted
}

//json:category=BalanceUpdateCategory(),kind=BalanceUpdateKind()
type BalanceUpdateLostAttestingRewards struct {
Delegate tz.PublicKeyHash `json:"delegate"`
Participation bool `json:"participation"`
Revelation bool `json:"revelation"`
}

func (*BalanceUpdateLostAttestingRewards) BalanceUpdateCategory() string {
return "lost_attesting_rewards"
}
func (*BalanceUpdateLostAttestingRewards) BalanceUpdateKind() core.BalanceUpdateKind {
return core.BalanceUpdateKindBurned
}

type BondID interface {
proto_016_PtMumbai.BondID
}

type SmartRollupBondID struct {
Address *tz.SmartRollupAddress `json:"address"`
}

func (SmartRollupBondID) BondID() {}

func init() {
encoding.RegisterEnum(&encoding.Enum[BondID]{
Variants: encoding.Variants[BondID]{
1: SmartRollupBondID{},
},
})
}

//json:category=BalanceUpdateCategory(),kind=BalanceUpdateKind()
type BalanceUpdateFrozenBonds struct {
Contract core.ContractID `json:"contract"`
BondID BondID `json:"bond_id"`
}

func (*BalanceUpdateFrozenBonds) BalanceUpdateCategory() string { return "frozen_bonds" }
func (*BalanceUpdateFrozenBonds) BalanceUpdateKind() core.BalanceUpdateKind {
return core.BalanceUpdateKindFreezer
}

type BalanceUpdateContents interface {
core.BalanceUpdateContents
}

func init() {
encoding.RegisterEnum(&encoding.Enum[BalanceUpdateContents]{
Variants: encoding.Variants[BalanceUpdateContents]{
0: (*BalanceUpdateContract)(nil),
2: BalanceUpdateBlockFees{},
4: (*BalanceUpdateDeposits)(nil),
5: BalanceUpdateNonceRevelationRewards{},
7: BalanceUpdateAttestingRewards{},
8: BalanceUpdateBakingRewards{},
9: BalanceUpdateBakingBonuses{},
11: BalanceUpdateStorageFees{},
12: BalanceUpdateDoubleSigningPunishments{},
13: (*BalanceUpdateLostAttestingRewards)(nil),
14: BalanceUpdateLiquidityBakingSubsidies{},
15: BalanceUpdateBurned{},
16: (*BalanceUpdateCommitments)(nil),
17: BalanceUpdateBootstrap{},
18: BalanceUpdateInvoice{},
19: BalanceUpdateInitialCommitments{},
20: BalanceUpdateMinted{},
21: (*BalanceUpdateFrozenBonds)(nil),
24: BalanceUpdateSmartRollupRefutationPunishments{},
25: BalanceUpdateSmartRollupRefutationRewards{},
26: (*BalanceUpdateUnstakedDeposits)(nil),
27: StakingDelegatorNumerator{},
28: StakingDelegateDenominator{},
},
})
}
Loading

0 comments on commit 87e2864

Please sign in to comment.