Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
67f829f
XC-293: Re-organize sol_rpc_types into sub-modules
lpahlavi Apr 14, 2025
0243fa4
XC-293: Clippy
lpahlavi Apr 14, 2025
535a8e6
XC-293: Clippy
lpahlavi Apr 14, 2025
d8e3142
XC-293: Add new types: part1
lpahlavi Apr 14, 2025
67eff6f
XC-293: Add new types: part2
lpahlavi Apr 15, 2025
7cb6bfe
Merge branch 'main' into lpahlavi/XC-293-get-transaction-v2
lpahlavi Apr 15, 2025
aacae82
XC-293: Clippy
lpahlavi Apr 15, 2025
11e2872
XC-293: Use OptionSerializer::or_skip
lpahlavi Apr 15, 2025
4a49327
XC-293: Add some unit tests
lpahlavi Apr 15, 2025
8384ecf
XC-293: Add end-to-end test
lpahlavi Apr 15, 2025
bdd3069
XC-293: Fix end-to-end test
lpahlavi Apr 15, 2025
2e5b5f6
XC-293: Clippy
lpahlavi Apr 15, 2025
1981470
XC-293: Rollback Candid changes
lpahlavi Apr 15, 2025
fc01635
XC-293: Print to stdout
lpahlavi Apr 15, 2025
f91e335
XC-293: Explicitely echo command outputs
lpahlavi Apr 15, 2025
ad43948
XC-293: Add Candid interface for getTransactionCyclesCost
lpahlavi Apr 15, 2025
9b32a69
XC-293: Add complete Candid interface
lpahlavi Apr 15, 2025
eb0f7b7
XC-293: Fix typo in examples.sh
lpahlavi Apr 15, 2025
a5a4675
XC-293: Remove unnecessary output in examples.sh
lpahlavi Apr 15, 2025
055997f
XC-293: Small bash fixes
lpahlavi Apr 15, 2025
f499758
XC-293: Remove quotes around $FLAGS
lpahlavi Apr 15, 2025
a2a35e8
XC-293: Adapt response size estimate for getBlock based on transactio…
lpahlavi Apr 15, 2025
e650430
XC-293: Increase response size estimate for get_transaction
lpahlavi Apr 15, 2025
0a6f8fa
XC-293: Fix indexing for getBlock response
lpahlavi Apr 15, 2025
20af877
XC-293: Add more cycles to getBlock call
lpahlavi Apr 15, 2025
1c7f4be
XC-293: Add more cycles to getBlock call
lpahlavi Apr 15, 2025
566e2ba
XC-293: Address review feedback
lpahlavi Apr 16, 2025
47b5964
XC-293: Clippy
lpahlavi Apr 16, 2025
9cf518a
XC-293: Address review feedback
lpahlavi Apr 16, 2025
f5a592a
XC-293: Add explicit try_from instead of try_into
lpahlavi Apr 17, 2025
fdb5640
XC-293: Clippy
lpahlavi Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ solana-message = "2.2.0"
solana-nonce = "2.2.0"
solana-program = "2.2.0"
solana-pubkey = "2.2.0"
solana-reward-info = "2.2.0"
solana-rpc-client-api = "2.2.0"
solana-signature = "2.2.0"
solana-signer = "2.2.0"
solana-transaction = "2.2.0"
solana-transaction-context = "2.2.0"
solana-transaction-error = "2.2.0"
solana-transaction-status-client-types = "2.2.0"
strum = { version = "0.27.0", features = ["derive"] }
thiserror = "2.0.12"
Expand All @@ -103,9 +106,12 @@ solana-message = { git = "https://github.com/dfinity/agave", tag = "323039e-js-f
solana-nonce = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-program = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-pubkey = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-reward-info = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-rpc-client-api = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-signer = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-signature = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-transaction = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-transaction-context = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-transaction-error = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-transaction-status-client-types = { git = "https://github.com/dfinity/agave", tag = "323039e-js-feature-flag" }
solana-system-interface = { git = "https://github.com/lpahlavi/solana-program-system.git" }
2 changes: 1 addition & 1 deletion canister/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ serde_with = { workspace = true }
candid_parser = { workspace = true }
proptest = { workspace = true }
solana-pubkey = { workspace = true }
solana-rpc-client-api = { workspace = true }
solana-signature = { workspace = true }

[features]
# WARNING: Disabling this feature will lead to some functionality not working anymore
Expand Down
26 changes: 24 additions & 2 deletions canister/scripts/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ GET_SLOT_PARAMS="(
opt record { minContextSlot = null; commitment = opt variant { finalized } },
)"
CYCLES=$(dfx canister call sol_rpc getSlotCyclesCost "$GET_SLOT_PARAMS" $FLAGS --output json | jq '.Ok' --raw-output || exit 1)
SLOT=$(dfx canister call sol_rpc getSlot "$GET_SLOT_PARAMS" $FLAGS --with-cycles "$CYCLES" --output json | jq '.Consistent.Ok' --raw-output || exit 1)
GET_SLOT_OUTPUT=$(dfx canister call sol_rpc getSlot "$GET_SLOT_PARAMS" $FLAGS --output json --with-cycles "$CYCLES" || exit 1)
SLOT=$(jq --raw-output '.Consistent.Ok' <<< "$GET_SLOT_OUTPUT")

# Fetch the latest finalized block
GET_BLOCK_PARAMS="(
Expand All @@ -36,11 +37,32 @@ GET_BLOCK_PARAMS="(
record {
slot = ${SLOT};
commitment = opt variant { finalized };
transactionDetails = opt variant { signatures };
maxSupportedTransactionVersion = null;
},
)"
CYCLES=$(dfx canister call sol_rpc getBlockCyclesCost "$GET_BLOCK_PARAMS" $FLAGS --output json | jq '.Ok' --raw-output || exit 1)
dfx canister call sol_rpc getBlock "$GET_BLOCK_PARAMS" $FLAGS --with-cycles "$CYCLES" || exit 1
GET_BLOCK_OUTPUT=$(dfx canister call sol_rpc getBlock "$GET_BLOCK_PARAMS" $FLAGS --output json --with-cycles "$CYCLES" || exit 1)
SIGNATURE=$(jq --raw-output '.Consistent.Ok[0].signatures[0][0]' <<< "$GET_BLOCK_OUTPUT")

# Fetch the first transaction in the retrieved block
GET_TRANSACTION_PARAMS="(
variant { Default = variant { Mainnet } },
opt record {
responseConsensus = opt variant {
Threshold = record { min = 2 : nat8; total = opt (3 : nat8) }
};
responseSizeEstimate = null;
},
record {
signature = \"${SIGNATURE}\";
commitment = opt variant { finalized };
encoding = opt variant{ base64 };
maxSupportedTransactionVersion = null;
},
)"
CYCLES=$(dfx canister call sol_rpc getTransactionCyclesCost "$GET_TRANSACTION_PARAMS" $FLAGS --output json | jq '.Ok' --raw-output || exit 1)
dfx canister call sol_rpc getTransaction "$GET_TRANSACTION_PARAMS" $FLAGS --with-cycles "$CYCLES" || exit 1

# TODO XC-339: Add end-to-end test for `sendTransaction` using `getSlot` and `getBlock`

Expand Down
202 changes: 196 additions & 6 deletions canister/sol_rpc_canister.did
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ type GetAccountInfoParams = record {
// Example: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
type Pubkey = text;

// Ed25519 signature as a base-58 encoded string.
// Example: "5LrcE2f6uvydKRquEJ8xp19heGxSvqsVbcqUeFoiWbXe8JNip7ftPQNTAVPyTK7ijVdpkzmKKaAQR7MWMmujAhXD"
type Signature = text;

// A Solana blockhash as a bse58-encoded string.
// Example: "DzfXchZJoLMG3cNftcf2sw7qatkkuwQf4xH15N5wkKAb"
type Blockhash = text;

// Solana account info.
type AccountInfo = record {
// Number of lamports assigned to this account.
Expand Down Expand Up @@ -241,6 +249,15 @@ type AccountEncoding = variant {
jsonParsed;
};

// The parameters for a Solana `getTransaction` RPC method call.
// TODO XC-293: documentation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

type GetTransactionParams = record {
signature: Signature;
commitment: opt CommitmentLevel;
maxSupportedTransactionVersion: opt nat8;
encoding: opt variant { base58; base64 };
};

// The parameters for a Solana `sendTransaction` RPC method call.
type SendTransactionParams = record {
// Fully-signed transaction, as encoded string.
Expand Down Expand Up @@ -283,6 +300,9 @@ type MultiGetAccountInfoResult = variant {
type GetBlockParams = record {
// Slot number of the block to fetch.
slot: Slot;
// Specifies what transaction details to include in the response.
// If this field is not specified, the default value of "none" will be used.
transactionDetails: opt TransactionDetails;
// The commitment describes how finalized a block is at that point in time.
commitment: opt variant { confirmed; finalized };
// The max transaction version to return in responses.
Expand All @@ -303,15 +323,18 @@ type Timestamp = int64;
type ConfirmedBlock = record {
// The blockhash of this block's parent, as base-58 encoded string; if the parent block is not
// available due to ledger cleanup, this field will return "11111111111111111111111111111111".
previousBlockhash: text;
previousBlockhash: Blockhash;
// The blockhash of this block, as base-58 encoded string.
blockhash: text;
blockhash: Blockhash;
// The slot index of this block's parent.
parentSlot: nat64;
// Estimated production time.
blockTime: opt Timestamp;
// The number of blocks beneath this block.
blockHeight: opt nat64;
// The signatures of the transactions in this block. Included if the request parameter `transactionDetails` is not
// `none`.
signatures: opt vec Signature;
};

// Represents the result of a call to the `getBlock` Solana RPC method.
Expand All @@ -324,6 +347,172 @@ type MultiGetBlockResult = variant {
Inconsistent : vec record { RpcSource; GetBlockResult };
};

// TODO XC-293: Format and add documentation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

type CompiledInstruction = record {
data : text;
accounts : blob;
programIdIndex : nat8;
stackHeight : opt nat32;
};
type EncodedTransaction = variant {
Binary : record { text; variant { base58; base64 } };
LegacyBinary : text;
};
type Instruction = variant { Compiled : CompiledInstruction };
type InnerInstructions = record {
instructions : vec Instruction;
index : nat8;
};
type InstructionError = variant {
ModifiedProgramId;
CallDepth;
Immutable;
GenericError;
ExecutableAccountNotRentExempt;
IncorrectAuthority;
PrivilegeEscalation;
ReentrancyNotAllowed;
InvalidInstructionData;
RentEpochModified;
IllegalOwner;
ComputationalBudgetExceeded;
ExecutableDataModified;
ExecutableLamportChange;
UnbalancedInstruction;
ProgramEnvironmentSetupFailure;
IncorrectProgramId;
UnsupportedSysvar;
UnsupportedProgramId;
AccountDataTooSmall;
NotEnoughAccountKeys;
AccountBorrowFailed;
InvalidRealloc;
AccountNotExecutable;
AccountNotRentExempt;
Custom : nat32;
AccountDataSizeChanged;
MaxAccountsDataAllocationsExceeded;
ExternalAccountLamportSpend;
ExternalAccountDataModified;
MissingAccount;
ProgramFailedToComplete;
MaxInstructionTraceLengthExceeded;
InvalidAccountData;
ProgramFailedToCompile;
ExecutableModified;
InvalidAccountOwner;
MaxSeedLengthExceeded;
AccountAlreadyInitialized;
AccountBorrowOutstanding;
ReadonlyDataModified;
UninitializedAccount;
InvalidArgument;
BorshIoError : text;
BuiltinProgramsMustConsumeComputeUnits;
MissingRequiredSignature;
DuplicateAccountOutOfSync;
MaxAccountsExceeded;
ArithmeticOverflow;
InvalidError;
InvalidSeeds;
DuplicateAccountIndex;
ReadonlyLamportChange;
InsufficientFunds;
};
type LoadedAddresses = record { writable : vec Pubkey; readonly : vec Pubkey };
type Reward = record {
lamports : int64;
commission : opt nat8;
pubkey : Pubkey;
rewardType : opt variant { Fee; Rent; Voting; Staking };
postBalance : nat64;
};
type TokenAmount = record {
decimals : nat8;
uiAmount : opt float64;
uiAmountString : text;
amount : text;
};
type TransactionDetails = variant { none; signatures };
type TransactionError = variant {
ProgramCacheHitMaxLimit;
InvalidAccountForFee;
AddressLookupTableNotFound;
MissingSignatureForFee;
WouldExceedAccountDataBlockLimit;
AccountInUse;
DuplicateInstruction : nat8;
AccountNotFound;
TooManyAccountLocks;
InvalidAccountIndex;
AlreadyProcessed;
WouldExceedAccountDataTotalLimit;
InvalidAddressLookupTableIndex;
SanitizeFailure;
ResanitizationNeeded;
InvalidRentPayingAccount;
MaxLoadedAccountsDataSizeExceeded;
InvalidAddressLookupTableData;
InvalidWritableAccount;
WouldExceedMaxAccountCostLimit;
InvalidLoadedAccountsDataSizeLimit;
InvalidProgramForExecution;
InstructionError : record { nat8; InstructionError };
InsufficientFundsForRent : record { account_index : nat8 };
UnsupportedVersion;
ClusterMaintenance;
WouldExceedMaxVoteCostLimit;
SignatureFailure;
ProgramAccountNotFound;
AccountLoadedTwice;
ProgramExecutionTemporarilyRestricted : record { account_index : nat8 };
AccountBorrowOutstanding;
WouldExceedMaxBlockCostLimit;
InvalidAddressLookupTableOwner;
InsufficientFundsForFee;
CallChainTooDeep;
UnbalancedTransaction;
CommitCancelled;
BlockhashNotFound;
};
type TransactionInfo = record {
blockTime : opt Timestamp;
meta : opt TransactionStatusMeta;
transaction : EncodedTransaction;
slot : nat64;
version : opt variant { Legacy; Number : nat8 };
};
type TransactionStatusMeta = record {
fee : nat64;
status : variant { Ok; Err: TransactionError };
innerInstructions : opt vec InnerInstructions;
postTokenBalances : opt vec TransactionTokenBalance;
preBalances : vec nat64;
postBalances : vec nat64;
returnData : opt record { data : text; programId : Pubkey };
logMessages : opt vec text;
rewards : opt vec Reward;
loadedAddresses : opt LoadedAddresses;
preTokenBalances : opt vec TransactionTokenBalance;
computeUnitsConsumed : opt nat64;
};
type TransactionTokenBalance = record {
owner : opt Pubkey;
mint : text;
programId : opt Pubkey;
accountIndex : nat8;
uiTokenAmount : TokenAmount;
};

// Represents the result of a call to the `getTransaction` Solana RPC method.
type GetTransactionResult = variant { Ok : opt TransactionInfo; Err : RpcError };

// Represents an aggregated result from multiple RPC calls to the `getTransaction` Solana RPC method.
type MultiGetTransactionResult = variant {
Consistent : GetTransactionResult;
Inconsistent : vec record { RpcSource; GetTransactionResult };
};

// Represents a Solana slot
type Slot = nat64;

Expand All @@ -336,11 +525,8 @@ type MultiGetSlotResult = variant {
Inconsistent : vec record { RpcSource; GetSlotResult };
};

// First transaction signature embedded in the transaction, as base-58 encoded string.
type TransactionId = text;

// Represents the result of a call to the `sendTransaction` Solana RPC method.
type SendTransactionResult = variant { Ok : TransactionId; Err : RpcError };
type SendTransactionResult = variant { Ok : Signature; Err : RpcError };

// Represents an aggregated result from multiple RPC calls to the `sendTransaction` Solana RPC method.
type MultiSendTransactionResult = variant {
Expand Down Expand Up @@ -435,6 +621,10 @@ service : (InstallArgs,) -> {
getSlot : (RpcSources, opt GetSlotRpcConfig, opt GetSlotParams) -> (MultiGetSlotResult);
getSlotCyclesCost : (RpcSources, opt GetSlotRpcConfig, opt GetSlotParams) -> (RequestCostResult) query;

// Call the Solana `getTransaction` RPC method and return the resulting slot.
getTransaction : (RpcSources, opt RpcConfig, GetTransactionParams) -> (MultiGetTransactionResult);
getTransactionCyclesCost : (RpcSources, opt RpcConfig, GetTransactionParams) -> (RequestCostResult) query;

// Call the Solana `sendTransaction` RPC method and return the resulting transaction ID.
sendTransaction : (RpcSources, opt RpcConfig, SendTransactionParams) -> (MultiSendTransactionResult);
sendTransactionCyclesCost : (RpcSources, opt RpcConfig, SendTransactionParams) -> (RequestCostResult) query;
Expand Down
Loading