diff --git a/cmd/generate-bindings/solana/anchor-go/generator/cre.go b/cmd/generate-bindings/solana/anchor-go/generator/cre.go index 902b44d1..7ba3df3b 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 , remainingAccounts []*solana.AccountMeta, computeConfig *solana.ComputeConfig) 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 caf0476a..157f5199 100644 --- a/cmd/generate-bindings/solana/testdata/data_storage/types.go +++ b/cmd/generate-bindings/solana/testdata/data_storage/types.go @@ -79,6 +79,7 @@ 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, @@ -210,6 +211,7 @@ 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, @@ -363,6 +365,7 @@ 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, @@ -460,6 +463,7 @@ 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, @@ -580,6 +584,7 @@ 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, @@ -700,6 +705,7 @@ 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,