-
Notifications
You must be signed in to change notification settings - Fork 1
Fix error handler, move api/solana=>api/spl, add lookup table support, rewardmanagerstate support #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix error handler, move api/solana=>api/spl, add lookup table support, rewardmanagerstate support #43
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ccb4c66
Fix error handler to change status code
rickyrombo 417fd65
move solana to spl to prevent name conflicts
rickyrombo 4b0238f
Add decoder for address lookup tables
rickyrombo 4c4aab2
Move account derivations and add RewardManagerState struct
rickyrombo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package spl | ||
|
|
||
| import ( | ||
| bin "github.com/gagliardetto/binary" | ||
| "github.com/gagliardetto/solana-go" | ||
| ) | ||
|
|
||
| type AddressLookupTableMeta struct { | ||
| DeactivationSlot uint64 | ||
| LastExtendedSlot uint64 | ||
| LastExtendedSlotStartIndex uint8 | ||
| Authority []solana.PublicKey | ||
| } | ||
|
|
||
| type AddressLookupTable struct { | ||
| State uint32 | ||
| Meta AddressLookupTableMeta | ||
| Addresses []solana.PublicKey | ||
| } | ||
|
|
||
| func (inst *AddressLookupTable) UnmarshalWithDecoder(decoder *bin.Decoder) error { | ||
| err := decoder.Decode(&inst.State) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = decoder.Decode(&inst.Meta) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = decoder.SetPosition(56) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for decoder.HasRemaining() { | ||
| pub := &solana.PublicKey{} | ||
| err = decoder.Decode(pub) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| inst.Addresses = append(inst.Addresses, *pub) | ||
| } | ||
| return err | ||
| } | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package reward_manager | ||
|
|
||
| import ( | ||
| "encoding/hex" | ||
| "strings" | ||
|
|
||
| "github.com/gagliardetto/solana-go" | ||
| ) | ||
|
|
||
| type RewardManagerState struct { | ||
| Version uint8 | ||
| TokenAccount solana.PublicKey | ||
| Manager solana.PublicKey | ||
| MinVotes uint8 | ||
| } | ||
|
|
||
| func deriveAuthority(programId solana.PublicKey, state solana.PublicKey) (solana.PublicKey, uint8, error) { | ||
| seeds := make([][]byte, 1) | ||
| seeds[0] = state.Bytes()[0:32] | ||
| return solana.FindProgramAddress(seeds, programId) | ||
| } | ||
|
|
||
| func deriveSender(programId solana.PublicKey, authority solana.PublicKey, ethAddress string) (solana.PublicKey, uint8, error) { | ||
| senderSeedPrefix := []byte(SenderSeedPrefix) | ||
| // Remove 0x and decode hex | ||
| decodedEthAddress, err := hex.DecodeString(strings.TrimPrefix(ethAddress, "0x")) | ||
| if err != nil { | ||
| return solana.PublicKey{}, 0, err | ||
| } | ||
| // Pad the eth address if necessary w/ leading 0 | ||
| senderSeed := make([]byte, len(senderSeedPrefix)+EthAddressByteLength) | ||
| copy(senderSeed, senderSeedPrefix) | ||
| copy(senderSeed[len(senderSeed)-len(decodedEthAddress):], decodedEthAddress) | ||
| return solana.FindProgramAddress([][]byte{authority.Bytes()[0:32], senderSeed}, programId) | ||
| } | ||
|
|
||
| func deriveAttestations(programId solana.PublicKey, authority solana.PublicKey, disbursementId string) (solana.PublicKey, uint8, error) { | ||
| attestationsSeed := make([]byte, len(AttestationsSeedPrefix)+len(disbursementId)) | ||
| copy(attestationsSeed, []byte(AttestationsSeedPrefix)) | ||
| copy(attestationsSeed[len([]byte(AttestationsSeedPrefix)):], disbursementId) | ||
| return solana.FindProgramAddress([][]byte{authority.Bytes()[0:32], attestationsSeed}, programId) | ||
| } | ||
|
|
||
| func deriveDisbursement(programId solana.PublicKey, authority solana.PublicKey, disbursementId string) (solana.PublicKey, uint8, error) { | ||
| disbursementSeed := make([]byte, len(DisbursementSeedPrefix)+len(disbursementId)) | ||
| copy(disbursementSeed, []byte(DisbursementSeedPrefix)) | ||
| copy(disbursementSeed[len([]byte(DisbursementSeedPrefix)):], disbursementId) | ||
| return solana.FindProgramAddress([][]byte{authority.Bytes()[0:32], disbursementSeed}, programId) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just int?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.rs/solana-address-lookup-table-interface/2.2.2/src/solana_address_lookup_table_interface/state.rs.html#49
https://docs.rs/solana-clock/latest/solana_clock/type.Slot.html