Skip to content

Instantly share code, notes, and snippets.

@kyranjamie
Last active June 5, 2022 23:43
Show Gist options
  • Save kyranjamie/11a6acaed43c0e9c3334bf2c002ebb96 to your computer and use it in GitHub Desktop.
Save kyranjamie/11a6acaed43c0e9c3334bf2c002ebb96 to your computer and use it in GitHub Desktop.
export interface PostConditionStx {
principal: PostConditionPrincipal;
condition_code: PostConditionFungibleConditionCode;
amount: string;
type: "stx";
}
export interface PostConditionFungible {
principal: PostConditionPrincipal;
condition_code: PostConditionFungibleConditionCode;
type: "fungible";
amount: string;
asset: {
asset_name: string;
contract_address: string;
contract_name: string;
};
}
export interface PostConditionNonFungible {
principal: PostConditionPrincipal;
condition_code: PostConditionNonFungibleConditionCode;
type: "non_fungible";
asset_value: string;
asset: {
asset_name: string;
contract_address: string;
contract_name: string;
};
}
/**
* A fungible condition code encodes a statement being made for either STX or a fungible token, with respect to the originating account.
*/
export type PostConditionFungibleConditionCode =
| "sent_equal_to"
| "sent_greater_than"
| "sent_greater_than_or_equal_to"
| "sent_less_than"
| "sent_less_than_or_equal_to";
export type PostConditionMode = "allow" | "deny";
/**
* A non-fungible condition code encodes a statement being made about a non-fungible token, with respect to whether or not the particular non-fungible token is owned by the account.
*/
export type PostConditionNonFungibleConditionCode = "sent" | "not_sent";
export type PostConditionPrincipalType = "principal_origin" | "principal_standard" | "principal_contract";
export type PostConditionPrincipal =
| {
/**
* String literal of type `PostConditionPrincipalType`
*/
type_id: "principal_origin";
}
| {
/**
* String literal of type `PostConditionPrincipalType`
*/
type_id: "principal_standard";
address: string;
}
| {
/**
* String literal of type `PostConditionPrincipalType`
*/
type_id: "principal_contract";
address: string;
contract_name: string;
};
export type PostConditionType = "stx" | "non_fungible" | "fungible";
export type PostCondition = PostConditionStx | PostConditionFungible | PostConditionNonFungible;
export type TransactionEventAssetType = "transfer" | "mint" | "burn";
/**
* Events types
*/
export type TransactionEventType =
| "smart_contract_log"
| "stx_asset"
| "fungible_token_asset"
| "non_fungible_token_asset";
/**
* Abstract transaction event. Only present in `smart_contract` and `contract_call` tx types.
*/
export interface TransactionEvent {
event_index: number;
event_type: TransactionEventType;
asset?: {
asset_event_type?: TransactionEventAssetType;
asset_id?: string;
sender?: string;
recipient?: string;
amount?: string;
value?: string;
};
contract_log?: {
contract_id: string;
topic: string;
value: string;
};
}
/**
* Describes representation of a Type-0 Stacks 2.0 transaction. https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md#type-0-transferring-an-asset
*/
export interface TokenTransferTransaction {
block_hash: string;
block_height: number;
tx_id: string;
tx_index: number;
tx_status: TransactionStatus;
/**
* Integer string (64-bit unsigned integer).
*/
fee_rate: string;
sender_address: string;
/**
* Denotes whether the originating account is the same as the paying account
*/
sponsored: boolean;
post_condition_mode: PostConditionMode;
tx_type: "token_transfer";
events: TransactionEvent[];
token_transfer: {
recipient_address: string;
/**
* Integer string (64-bit unsigned integer)
*/
amount: string;
/**
* Hex encoded arbitrary message, up to 34 bytes length (should try decoding to an ASCII string)
*/
memo: string;
};
}
/**
* Describes representation of a Type-1 Stacks 2.0 transaction. https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md#type-1-instantiating-a-smart-contract
*/
export interface SmartContractTransaction {
block_hash: string;
block_height: number;
tx_id: string;
tx_index: number;
tx_status: TransactionStatus;
/**
* Integer string (64-bit unsigned integer).
*/
fee_rate: string;
sender_address: string;
/**
* Denotes whether the originating account is the same as the paying account
*/
sponsored: boolean;
post_condition_mode: PostConditionMode;
tx_type: "smart_contract";
events: TransactionEvent[];
smart_contract: {
contract_id: string;
/**
* Clarity code of the smart contract being deployed
*/
source_code: string;
};
post_conditions?: PostCondition[];
}
/**
* Describes representation of a Type 2 Stacks 2.0 transaction: Contract Call
*/
export interface ContractCallTransaction {
block_hash: string;
block_height: number;
tx_id: string;
tx_index: number;
tx_status: TransactionStatus;
/**
* Integer string (64-bit unsigned integer).
*/
fee_rate: string;
sender_address: string;
/**
* Denotes whether the originating account is the same as the paying account
*/
sponsored: boolean;
post_condition_mode: PostConditionMode;
tx_type: "contract_call";
events: TransactionEvent[];
contract_call: {
contract_id: string;
/**
* Name of the Clarity function to be invoked
*/
function_name: string;
function_args?: string[];
};
post_conditions: PostCondition[];
}
/**
* Describes representation of a Type 3 Stacks 2.0 transaction: Poison Microblock
*/
export interface PoisonMicroblockTransaction {
block_hash: string;
block_height: number;
tx_id: string;
tx_index: number;
tx_status: TransactionStatus;
/**
* Integer string (64-bit unsigned integer).
*/
fee_rate: string;
sender_address: string;
/**
* Denotes whether the originating account is the same as the paying account
*/
sponsored: boolean;
post_condition_mode: PostConditionMode;
tx_type: "poison_microblock";
}
/**
* Describes representation of a Type 3 Stacks 2.0 transaction: Poison Microblock
*/
export interface CoinbaseTransaction {
block_hash: string;
block_height: number;
tx_id: string;
tx_index: number;
tx_status: TransactionStatus;
/**
* Integer string (64-bit unsigned integer).
*/
fee_rate: string;
sender_address: string;
/**
* Denotes whether the originating account is the same as the paying account
*/
sponsored: boolean;
post_condition_mode: PostConditionMode;
tx_type: "coinbase";
coinbase_payload: {
/**
* Hex encoded 32-byte scratch space for block leader's use
*/
data: string;
};
}
/**
* All states a transaction can have
*/
export type TransactionStatus = "success" | "pending" | "failed";
/**
* Describes all transaction types on Stacks 2.0 blockchain
*/
export type Transaction =
| TokenTransferTransaction
| SmartContractTransaction
| ContractCallTransaction
| PoisonMicroblockTransaction
| CoinbaseTransaction;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment