Skip to content

Commit c7a6f82

Browse files
committed
Add support for versioned transactions
1 parent 7948b20 commit c7a6f82

File tree

17 files changed

+589
-232
lines changed

17 files changed

+589
-232
lines changed

pkg/code/async/geyser/external_deposit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func initiateExternalDepositIntoVm(ctx context.Context, data code_data.Provider,
117117
return errors.Wrap(err, "error getting vta location in memory")
118118
}
119119

120-
txn := solana.NewTransaction(
120+
txn := solana.NewLegacyTransaction(
121121
vmConfig.Authority.PublicKey().ToBytes(),
122122
memo.Instruction(codeVmDepositMemoValue),
123123
compute_budget.SetComputeUnitPrice(1_000),

pkg/code/async/nonce/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (p *service) createNonceAccountTx(ctx context.Context, nonce *nonce.Record)
169169
),
170170
}
171171

172-
tx := solana.NewTransaction(subPub, instructions...)
172+
tx := solana.NewLegacyTransaction(subPub, instructions...)
173173

174174
bh, err := p.getLatestBlockhash(ctx)
175175
if err != nil {

pkg/code/async/sequencer/testutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (h *mockFulfillmentHandler) MakeOnDemandTransaction(ctx context.Context, fu
4747
return nil, nil, errors.New("not supported")
4848
}
4949

50-
txn := solana.NewTransaction(common.GetSubsidizer().PublicKey().ToBytes(), memo.Instruction(selectedNonce.Account.PublicKey().ToBase58()))
50+
txn := solana.NewLegacyTransaction(common.GetSubsidizer().PublicKey().ToBytes(), memo.Instruction(selectedNonce.Account.PublicKey().ToBase58()))
5151
return &txn, nil, nil
5252
}
5353

pkg/code/async/sequencer/worker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (e *workerTestEnv) createAnyFulfillmentInState(t *testing.T, state fulfillm
271271
fakeCodeAccouht := testutil.NewRandomAccount(t)
272272
fakeNonceAccount := testutil.NewRandomAccount(t)
273273

274-
txn := solana.NewTransaction(
274+
txn := solana.NewLegacyTransaction(
275275
fakeCodeAccouht.PublicKey().ToBytes(),
276276
system.AdvanceNonce(fakeNonceAccount.PublicKey().ToBytes(), fakeCodeAccouht.PublicKey().ToBytes()),
277277
)
@@ -361,7 +361,7 @@ func (e *workerTestEnv) assertFulfillmentCreatedOnDemand(t *testing.T, id uint64
361361
require.NotNil(t, fulfillmentRecord.Blockhash)
362362
require.NotEmpty(t, fulfillmentRecord.Data)
363363

364-
expectedTxn := solana.NewTransaction(common.GetSubsidizer().PublicKey().ToBytes(), memo.Instruction(nonceAddress))
364+
expectedTxn := solana.NewLegacyTransaction(common.GetSubsidizer().PublicKey().ToBytes(), memo.Instruction(nonceAddress))
365365
expectedTxn.Sign(e.subsidizer.PrivateKey().ToBytes())
366366
expectedSignature := base58.Encode(expectedTxn.Signature())
367367

pkg/code/data/blockchain.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const (
1919

2020
type BlockchainData interface {
2121
SubmitBlockchainTransaction(ctx context.Context, tx *solana.Transaction) (solana.Signature, error)
22-
RequestBlockchainAirdrop(ctx context.Context, account string, amount uint64) (solana.Signature, error)
2322

2423
GetBlockchainAccountInfo(ctx context.Context, account string, commitment solana.Commitment) (*solana.AccountInfo, error)
2524
GetBlockchainAccountDataAfterBlock(ctx context.Context, account string, slot uint64) ([]byte, uint64, error)
@@ -70,23 +69,6 @@ func (dp *BlockchainProvider) SubmitBlockchainTransaction(ctx context.Context, t
7069
return res, err
7170
}
7271

73-
func (dp *BlockchainProvider) RequestBlockchainAirdrop(ctx context.Context, account string, amount uint64) (solana.Signature, error) {
74-
tracer := metrics.TraceMethodCall(ctx, blockchainProviderMetricsName, "RequestBlockchainAirdrop")
75-
defer tracer.End()
76-
77-
pubkey, err := base58.Decode(account)
78-
if err != nil {
79-
return solana.Signature{}, err
80-
}
81-
82-
res, err := dp.sc.RequestAirdrop(pubkey, amount, solana.CommitmentProcessed)
83-
if err != nil {
84-
tracer.OnError(err)
85-
}
86-
87-
return res, err
88-
}
89-
9072
func (dp *BlockchainProvider) GetBlockchainAccountInfo(ctx context.Context, account string, commitment solana.Commitment) (*solana.AccountInfo, error) {
9173
tracer := metrics.TraceMethodCall(ctx, blockchainProviderMetricsName, "GetBlockchainAccountInfo")
9274
defer tracer.End()

pkg/code/transaction/transaction.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ func MakeNoncedTransaction(nonce *Nonce, instructions ...solana.Instruction) (so
3333

3434
instructions = append([]solana.Instruction{advanceNonceInstruction}, instructions...)
3535

36-
txn := solana.NewTransaction(payer.PublicKey().ToBytes(), instructions...)
36+
txn := solana.NewLegacyTransaction(payer.PublicKey().ToBytes(), instructions...)
3737
txn.SetBlockhash(nonce.Blockhash)
38-
3938
return txn, nil
4039
}
4140

pkg/solana/address_lookup_table.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

pkg/solana/binary/utils.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ func PutKey32(dst []byte, src []byte, offset *int) {
1010
*offset += ed25519.PublicKeySize
1111
}
1212

13-
func PutOptionalKey32(dst []byte, src []byte, offset *int) {
13+
func PutOptionalKey32(dst []byte, src []byte, offset *int, optionSize int) {
1414
if len(src) > 0 {
1515
dst[0] = 1
16-
copy(dst[4:], src)
16+
copy(dst[optionSize:], src)
1717
}
1818

19-
*offset += 4 + ed25519.PublicKeySize
19+
*offset += optionSize + ed25519.PublicKeySize
2020
}
2121

2222
func PutUint64(dst []byte, v uint64, offset *int) {
@@ -34,12 +34,12 @@ func PutUint8(dst []byte, v uint8, offset *int) {
3434
*offset += 1
3535
}
3636

37-
func PutOptionalUint64(dst []byte, v *uint64, offset *int) {
37+
func PutOptionalUint64(dst []byte, v *uint64, offset *int, optionSize int) {
3838
if v != nil {
3939
dst[0] = 1
40-
binary.LittleEndian.PutUint64(dst[4:], *v)
40+
binary.LittleEndian.PutUint64(dst[optionSize:], *v)
4141
}
42-
*offset += 4 + 8
42+
*offset += optionSize + 8
4343
}
4444

4545
func GetKey32(src []byte, dst *ed25519.PublicKey, offset *int) {
@@ -71,10 +71,10 @@ func GetUint8(src []byte, dst *uint8, offset *int) {
7171
*offset += 1
7272
}
7373

74-
func GetOptionalUint64(src []byte, dst **uint64, offset *int) {
74+
func GetOptionalUint64(src []byte, dst **uint64, offset *int, optionSize int) {
7575
if src[0] == 1 {
76-
val := binary.LittleEndian.Uint64(src[4:])
76+
val := binary.LittleEndian.Uint64(src[optionSize:])
7777
*dst = &val
7878
}
79-
*offset += 4 + 8
79+
*offset += optionSize + 8
8080
}

pkg/solana/client.go

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ type Client interface {
178178
GetConfirmationStatus(Signature, Commitment) (bool, error)
179179
GetConfirmedBlock(slot uint64) (*Block, error)
180180
GetConfirmedBlocksWithLimit(start, limit uint64) ([]uint64, error)
181-
GetConfirmedTransaction(Signature) (ConfirmedTransaction, error)
182-
GetMinimumBalanceForRentExemption(size uint64) (lamports uint64, err error)
181+
GetFilteredProgramAccounts(program ed25519.PublicKey, offset uint, filterValue []byte) ([]string, uint64, error)
183182
GetLatestBlockhash() (Blockhash, error)
183+
GetMinimumBalanceForRentExemption(size uint64) (lamports uint64, err error)
184184
GetSignatureStatus(Signature, Commitment) (*SignatureStatus, error)
185185
GetSignatureStatuses([]Signature) ([]*SignatureStatus, error)
186186
GetSignaturesForAddress(owner ed25519.PublicKey, commitment Commitment, limit uint64, before, until string) ([]*TransactionSignature, error)
@@ -189,8 +189,6 @@ type Client interface {
189189
GetTokenAccountsByOwner(owner, mint ed25519.PublicKey) ([]ed25519.PublicKey, error)
190190
GetTransaction(Signature, Commitment) (ConfirmedTransaction, error)
191191
GetTransactionTokenBalances(Signature) (TransactionTokenBalances, error)
192-
GetFilteredProgramAccounts(program ed25519.PublicKey, offset uint, filterValue []byte) ([]string, uint64, error)
193-
RequestAirdrop(ed25519.PublicKey, uint64, Commitment) (Signature, error)
194192
SubmitTransaction(Transaction, Commitment) (Signature, error)
195193
}
196194

@@ -528,47 +526,6 @@ func (c *client) GetConfirmedBlocksWithLimit(start, limit uint64) (slots []uint6
528526
return slots, c.call(&slots, "getConfirmedBlocksWithLimit", start, limit)
529527
}
530528

531-
func (c *client) GetConfirmedTransaction(sig Signature) (ConfirmedTransaction, error) {
532-
type rpcResponse struct {
533-
Slot uint64 `json:"slot"`
534-
Transaction []string `json:"transaction"` // [val, encoding]
535-
Meta *struct {
536-
Err interface{} `json:"err"`
537-
} `json:"meta"`
538-
}
539-
540-
var resp *rpcResponse
541-
if err := c.call(&resp, "getConfirmedTransaction", base58.Encode(sig[:]), "base64"); err != nil {
542-
return ConfirmedTransaction{}, err
543-
}
544-
545-
if resp == nil {
546-
return ConfirmedTransaction{}, ErrSignatureNotFound
547-
}
548-
549-
txn := ConfirmedTransaction{
550-
Slot: resp.Slot,
551-
}
552-
553-
var err error
554-
rawTxn, err := base64.StdEncoding.DecodeString(resp.Transaction[0])
555-
if err != nil {
556-
return txn, errors.Wrap(err, "failed to decode transaction")
557-
}
558-
if err := txn.Transaction.Unmarshal(rawTxn); err != nil {
559-
return txn, errors.Wrap(err, "failed to unmarshal transaction")
560-
}
561-
562-
if resp.Meta != nil {
563-
txn.Err, err = ParseTransactionError(resp.Meta.Err)
564-
if err != nil {
565-
return txn, errors.Wrap(err, "failed to parse transaction result")
566-
}
567-
}
568-
569-
return txn, nil
570-
}
571-
572529
func (c *client) GetTransaction(sig Signature, commitment Commitment) (ConfirmedTransaction, error) {
573530
type rpcResponse struct {
574531
Slot uint64 `json:"slot"`
@@ -578,11 +535,13 @@ func (c *client) GetTransaction(sig Signature, commitment Commitment) (Confirmed
578535
}
579536

580537
config := struct {
581-
Commitment string `json:"commitment"`
582-
Encoding string `json:"encoding"`
538+
Commitment string `json:"commitment"`
539+
Encoding string `json:"encoding"`
540+
MaxSupportedTransactionVersion int `json:"maxSupportedTransactionVersion"`
583541
}{
584-
Commitment: commitment.Commitment,
585-
Encoding: "base64",
542+
Commitment: commitment.Commitment,
543+
Encoding: "base64",
544+
MaxSupportedTransactionVersion: 0,
586545
}
587546

588547
var resp *rpcResponse
@@ -935,27 +894,6 @@ func (c *client) GetAccountDataAfterBlock(account ed25519.PublicKey, slot uint64
935894
return rawData, unmarshalledGetAccountInfoResp.Context.Slot, nil
936895
}
937896

938-
func (c *client) RequestAirdrop(account ed25519.PublicKey, lamports uint64, commitment Commitment) (Signature, error) {
939-
var sigStr string
940-
if err := c.call(&sigStr, "requestAirdrop", base58.Encode(account[:]), lamports, commitment); err != nil {
941-
return Signature{}, errors.Wrapf(err, "requestAirdrop() failed to send request")
942-
}
943-
944-
sigBytes, err := base58.Decode(sigStr)
945-
if err != nil {
946-
return Signature{}, errors.Wrap(err, "invalid signature in response")
947-
}
948-
949-
var sig Signature
950-
copy(sig[:], sigBytes)
951-
952-
if sig == (Signature{}) {
953-
return Signature{}, errors.New("empty signature returned")
954-
}
955-
956-
return sig, nil
957-
}
958-
959897
func (c *client) GetConfirmationStatus(sig Signature, commitment Commitment) (bool, error) {
960898
type response struct {
961899
Value bool `json:"value"`

0 commit comments

Comments
 (0)