Code Generation Produced Conflicts between Account and Instruction Struct
Opened this issue ยท 2 comments
Currently, if the IDL lists the same name for an account and an instruction, this will produce go code in which the account name and the instruction name will be the same. For example the IDl for the token-swap program here will yield
type Swap struct {
Version uint8
IsInitialized bool
BumpSeed uint8
TokenProgramId ag_solanago.PublicKey
TokenA ag_solanago.PublicKey
TokenB ag_solanago.PublicKey
PoolMint ag_solanago.PublicKey
TokenAMint ag_solanago.PublicKey
TokenBMint ag_solanago.PublicKey
PoolFeeAccount ag_solanago.PublicKey
Fees Fees
SwapCurve SwapCurve
}
and
// Swap is the `swap` instruction.
type Swap struct {
AmountIn *uint64
MinimumAmountOut *uint64
// [0] = [] swap
//
// [1] = [] authority
//
// [2] = [SIGNER] userTransferAuthority
//
// [3] = [WRITE] source
//
// [4] = [WRITE] swapSource
//
// [5] = [WRITE] swapDestination
//
// [6] = [WRITE] destination
//
// [7] = [WRITE] poolMint
//
// [8] = [WRITE] poolFee
//
// [9] = [] tokenProgram
ag_solanago.AccountMetaSlice `bin:"-"`
}
One Possible fix can be to introduce a flag to add a custom suffix to the account struct (or the instruction struct).
In this example with a custom account suffix of Account
we would get
type SwapAccount struct {
Version uint8
IsInitialized bool
BumpSeed uint8
TokenProgramId ag_solanago.PublicKey
TokenA ag_solanago.PublicKey
TokenB ag_solanago.PublicKey
PoolMint ag_solanago.PublicKey
TokenAMint ag_solanago.PublicKey
TokenBMint ag_solanago.PublicKey
PoolFeeAccount ag_solanago.PublicKey
Fees Fees
SwapCurve SwapCurve
}
// Swap is the `swap` instruction.
type Swap struct {
AmountIn *uint64
MinimumAmountOut *uint64
// [0] = [] swap
//
// [1] = [] authority
//
// [2] = [SIGNER] userTransferAuthority
//
// [3] = [WRITE] source
//
// [4] = [WRITE] swapSource
//
// [5] = [WRITE] swapDestination
//
// [6] = [WRITE] destination
//
// [7] = [WRITE] poolMint
//
// [8] = [WRITE] poolFee
//
// [9] = [] tokenProgram
ag_solanago.AccountMetaSlice `bin:"-"`
}
Yep, what you're describing is totally a bug.
The whole anchor-go package needs to be refactored from top to bottom ๐
I'll get to it (eventually).
And one of the things that would need to be done is to split the various generated stuff into separate folders (but even before that, there's a lot more).
Yep, what you're describing is totally a bug.
The whole anchor-go package needs to be refactored from top to bottom ๐
I'll get to it (eventually).
And one of the things that would need to be done is to split the various generated stuff into separate folders (but even before that, there's a lot more).
You might like what we're building for grizzlython ๐ dcaf labs is working on some code gen tooling, forked/refactored from anchor-go