From b4cbf3afe75935de83e471e3a65ede05efe07131 Mon Sep 17 00:00:00 2001 From: Vladimir Shchukin Date: Tue, 7 Apr 2026 08:57:14 -0400 Subject: [PATCH] document forwarder prefix --- .../solana/anchor-go/generator/cre.go | 14 +++- .../solana/testdata/data_storage/types.go | 72 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/cmd/generate-bindings/solana/anchor-go/generator/cre.go b/cmd/generate-bindings/solana/anchor-go/generator/cre.go index b17c136b..58247715 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/cre.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/cre.go @@ -63,10 +63,22 @@ func creWriteReportErrorBlock() Code { return code } -// func (c *DataStorage) WriteReportFrom(runtime cre.Runtime, input , accountList []solanago.PublicKey) cre.Promise[*solana.WriteReportReply] { func creWriteReportFromStructs(exportedAccountName string, g *Generator) Code { code := Empty() declarerName := newWriteReportFromInstructionFuncName(exportedAccountName) + code.Commentf("%s encodes the input struct, hashes the provided accounts,", declarerName) + code.Comment("generates a signed report, and submits it via WriteReport.") + code.Comment("") + code.Comment("remainingAccounts must follow the keystone-forwarder account layout:") + code.Comment(" - Index 0: forwarderState – the forwarder program's state account.") + code.Comment(" - Index 1: forwarderAuthority – PDA derived from seeds") + code.Comment(" [\"forwarder\", forwarderState, receiverProgram] under the forwarder program ID.") + code.Comment(" - Index 2+: receiver-specific accounts required by the target program.") + code.Comment("") + code.Comment("The full slice is hashed (via CalculateAccountsHash) into the report and forwarded") + code.Comment("as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1") + code.Comment("before CPI-ing into the receiver, so they must be present and correctly ordered.") + code.Line() code.Func(). Params(Id("c").Op("*").Id(tools.ToCamelUpper(g.options.Package))). // method receiver Id(declarerName). diff --git a/cmd/generate-bindings/solana/testdata/data_storage/types.go b/cmd/generate-bindings/solana/testdata/data_storage/types.go index 29470c23..25f852cd 100644 --- a/cmd/generate-bindings/solana/testdata/data_storage/types.go +++ b/cmd/generate-bindings/solana/testdata/data_storage/types.go @@ -79,6 +79,18 @@ func (c *Codec) EncodeAccessLoggedStruct(in AccessLogged) ([]byte, error) { return in.Marshal() } +// WriteReportFromAccessLogged encodes the input struct, hashes the provided accounts, +// generates a signed report, and submits it via WriteReport. +// +// remainingAccounts must follow the keystone-forwarder account layout: +// - Index 0: forwarderState – the forwarder program's state account. +// - Index 1: forwarderAuthority – PDA derived from seeds +// ["forwarder", forwarderState, receiverProgram] under the forwarder program ID. +// - Index 2+: receiver-specific accounts required by the target program. +// +// The full slice is hashed (via CalculateAccountsHash) into the report and forwarded +// as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1 +// before CPI-ing into the receiver, so they must be present and correctly ordered. func (c *DataStorage) WriteReportFromAccessLogged( runtime cre.Runtime, input AccessLogged, @@ -191,6 +203,18 @@ func (c *Codec) EncodeDataAccountStruct(in DataAccount) ([]byte, error) { return in.Marshal() } +// WriteReportFromDataAccount encodes the input struct, hashes the provided accounts, +// generates a signed report, and submits it via WriteReport. +// +// remainingAccounts must follow the keystone-forwarder account layout: +// - Index 0: forwarderState – the forwarder program's state account. +// - Index 1: forwarderAuthority – PDA derived from seeds +// ["forwarder", forwarderState, receiverProgram] under the forwarder program ID. +// - Index 2+: receiver-specific accounts required by the target program. +// +// The full slice is hashed (via CalculateAccountsHash) into the report and forwarded +// as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1 +// before CPI-ing into the receiver, so they must be present and correctly ordered. func (c *DataStorage) WriteReportFromDataAccount( runtime cre.Runtime, input DataAccount, @@ -325,6 +349,18 @@ func (c *Codec) EncodeDynamicEventStruct(in DynamicEvent) ([]byte, error) { return in.Marshal() } +// WriteReportFromDynamicEvent encodes the input struct, hashes the provided accounts, +// generates a signed report, and submits it via WriteReport. +// +// remainingAccounts must follow the keystone-forwarder account layout: +// - Index 0: forwarderState – the forwarder program's state account. +// - Index 1: forwarderAuthority – PDA derived from seeds +// ["forwarder", forwarderState, receiverProgram] under the forwarder program ID. +// - Index 2+: receiver-specific accounts required by the target program. +// +// The full slice is hashed (via CalculateAccountsHash) into the report and forwarded +// as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1 +// before CPI-ing into the receiver, so they must be present and correctly ordered. func (c *DataStorage) WriteReportFromDynamicEvent( runtime cre.Runtime, input DynamicEvent, @@ -403,6 +439,18 @@ func (c *Codec) EncodeNoFieldsStruct(in NoFields) ([]byte, error) { return in.Marshal() } +// WriteReportFromNoFields encodes the input struct, hashes the provided accounts, +// generates a signed report, and submits it via WriteReport. +// +// remainingAccounts must follow the keystone-forwarder account layout: +// - Index 0: forwarderState – the forwarder program's state account. +// - Index 1: forwarderAuthority – PDA derived from seeds +// ["forwarder", forwarderState, receiverProgram] under the forwarder program ID. +// - Index 2+: receiver-specific accounts required by the target program. +// +// The full slice is hashed (via CalculateAccountsHash) into the report and forwarded +// as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1 +// before CPI-ing into the receiver, so they must be present and correctly ordered. func (c *DataStorage) WriteReportFromNoFields( runtime cre.Runtime, input NoFields, @@ -504,6 +552,18 @@ func (c *Codec) EncodeUpdateReservesStruct(in UpdateReserves) ([]byte, error) { return in.Marshal() } +// WriteReportFromUpdateReserves encodes the input struct, hashes the provided accounts, +// generates a signed report, and submits it via WriteReport. +// +// remainingAccounts must follow the keystone-forwarder account layout: +// - Index 0: forwarderState – the forwarder program's state account. +// - Index 1: forwarderAuthority – PDA derived from seeds +// ["forwarder", forwarderState, receiverProgram] under the forwarder program ID. +// - Index 2+: receiver-specific accounts required by the target program. +// +// The full slice is hashed (via CalculateAccountsHash) into the report and forwarded +// as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1 +// before CPI-ing into the receiver, so they must be present and correctly ordered. func (c *DataStorage) WriteReportFromUpdateReserves( runtime cre.Runtime, input UpdateReserves, @@ -605,6 +665,18 @@ func (c *Codec) EncodeUserDataStruct(in UserData) ([]byte, error) { return in.Marshal() } +// WriteReportFromUserData encodes the input struct, hashes the provided accounts, +// generates a signed report, and submits it via WriteReport. +// +// remainingAccounts must follow the keystone-forwarder account layout: +// - Index 0: forwarderState – the forwarder program's state account. +// - Index 1: forwarderAuthority – PDA derived from seeds +// ["forwarder", forwarderState, receiverProgram] under the forwarder program ID. +// - Index 2+: receiver-specific accounts required by the target program. +// +// The full slice is hashed (via CalculateAccountsHash) into the report and forwarded +// as WriteCreReportRequest.RemainingAccounts. The on-chain forwarder strips indices 0 and 1 +// before CPI-ing into the receiver, so they must be present and correctly ordered. func (c *DataStorage) WriteReportFromUserData( runtime cre.Runtime, input UserData,