scalar Address

scalar AssetId

type Balance {
	owner: Address!
	amount: U64!
	assetId: AssetId!
}

type BalanceConnection {
	"""
	Information to aid in pagination.
	"""
	pageInfo: PageInfo!
	"""
	A list of edges.
	"""
	edges: [BalanceEdge!]!
	"""
	A list of nodes.
	"""
	nodes: [Balance!]!
}

"""
An edge in a connection.
"""
type BalanceEdge {
	"""
	A cursor for use in pagination
	"""
	cursor: String!
	"""
	The item at the end of the edge
	"""
	node: Balance!
}

input BalanceFilterInput {
	"""
	Filter coins based on the `owner` field
	"""
	owner: Address!
}

type Block {
	id: BlockId!
	header: Header!
	consensus: Consensus!
	transactions: [Transaction!]!
}

type BlockConnection {
	"""
	Information to aid in pagination.
	"""
	pageInfo: PageInfo!
	"""
	A list of edges.
	"""
	edges: [BlockEdge!]!
	"""
	A list of nodes.
	"""
	nodes: [Block!]!
}

"""
An edge in a connection.
"""
type BlockEdge {
	"""
	A cursor for use in pagination
	"""
	cursor: String!
	"""
	The item at the end of the edge
	"""
	node: Block!
}

scalar BlockId


input Breakpoint {
	contract: ContractId!
	pc: U64!
}

scalar Bytes32

type ChainInfo {
	name: String!
	latestBlock: Block!
	baseChainHeight: U32!
	peerCount: Int!
	consensusParameters: ConsensusParameters!
}

type ChangeOutput {
	to: Address!
	amount: U64!
	assetId: AssetId!
}

type Coin {
	utxoId: UtxoId!
	owner: Address!
	amount: U64!
	assetId: AssetId!
	maturity: U32!
	"""
	TxPointer - the height of the block this coin was created in
	"""
	blockCreated: U32!
	"""
	TxPointer - the index of the transaction that created this coin
	"""
	txCreatedIdx: U64!
}

type CoinConnection {
	"""
	Information to aid in pagination.
	"""
	pageInfo: PageInfo!
	"""
	A list of edges.
	"""
	edges: [CoinEdge!]!
	"""
	A list of nodes.
	"""
	nodes: [Coin!]!
}

"""
An edge in a connection.
"""
type CoinEdge {
	"""
	A cursor for use in pagination
	"""
	cursor: String!
	"""
	The item at the end of the edge
	"""
	node: Coin!
}

input CoinFilterInput {
	"""
	Returns coins owned by the `owner`.
	"""
	owner: Address!
	"""
	Returns coins only with `asset_id`.
	"""
	assetId: AssetId
}

type CoinOutput {
	to: Address!
	amount: U64!
	assetId: AssetId!
}

"""
The schema analog of the [`coins::CoinType`].
"""
union CoinType = Coin | MessageCoin

union Consensus = Genesis | PoAConsensus

type ConsensusParameters {
	contractMaxSize: U64!
	maxInputs: U64!
	maxOutputs: U64!
	maxWitnesses: U64!
	maxGasPerTx: U64!
	maxScriptLength: U64!
	maxScriptDataLength: U64!
	maxStorageSlots: U64!
	maxPredicateLength: U64!
	maxPredicateDataLength: U64!
	maxGasPerPredicate: U64!
	gasPriceFactor: U64!
	gasPerByte: U64!
	maxMessageDataLength: U64!
	chainId: U64!
}

type Contract {
	id: ContractId!
	bytecode: HexString!
	salt: Salt!
}

type ContractBalance {
	contract: ContractId!
	amount: U64!
	assetId: AssetId!
}

type ContractBalanceConnection {
	"""
	Information to aid in pagination.
	"""
	pageInfo: PageInfo!
	"""
	A list of edges.
	"""
	edges: [ContractBalanceEdge!]!
	"""
	A list of nodes.
	"""
	nodes: [ContractBalance!]!
}

"""
An edge in a connection.
"""
type ContractBalanceEdge {
	"""
	A cursor for use in pagination
	"""
	cursor: String!
	"""
	The item at the end of the edge
	"""
	node: ContractBalance!
}

input ContractBalanceFilterInput {
	"""
	Filter assets based on the `contractId` field
	"""
	contract: ContractId!
}

type ContractCreated {
	contract: Contract!
	stateRoot: Bytes32!
}

scalar ContractId

type ContractOutput {
	inputIndex: Int!
	balanceRoot: Bytes32!
	stateRoot: Bytes32!
}

input ExcludeInput {
	"""
	Utxos to exclude from the selection.
	"""
	utxos: [UtxoId!]!
	"""
	Messages to exclude from the selection.
	"""
	messages: [Nonce!]!
}

type FailureStatus {
	block: Block!
	time: Tai64Timestamp!
	reason: String!
	programState: ProgramState
}


type Genesis {
	"""
	The chain configs define what consensus type to use, what settlement layer to use,
	rules of block validity, etc.
	"""
	chainConfigHash: Bytes32!
	"""
	The Binary Merkle Tree root of all genesis coins.
	"""
	coinsRoot: Bytes32!
	"""
	The Binary Merkle Tree root of state, balances, contracts code hash of each contract.
	"""
	contractsRoot: Bytes32!
	"""
	The Binary Merkle Tree root of all genesis messages.
	"""
	messagesRoot: Bytes32!
}

type Header {
	"""
	Hash of the header
	"""
	id: BlockId!
	"""
	The layer 1 height of messages and events to include since the last layer 1 block number.
	"""
	daHeight: U64!
	"""
	Number of transactions in this block.
	"""
	transactionsCount: U64!
	"""
	Number of message receipts in this block.
	"""
	messageReceiptCount: U64!
	"""
	Merkle root of transactions.
	"""
	transactionsRoot: Bytes32!
	"""
	Merkle root of message receipts in this block.
	"""
	messageReceiptRoot: Bytes32!
	"""
	Fuel block height.
	"""
	height: U32!
	"""
	Merkle root of all previous block header hashes.
	"""
	prevRoot: Bytes32!
	"""
	The block producer time.
	"""
	time: Tai64Timestamp!
	"""
	Hash of the application header.
	"""
	applicationHash: Bytes32!
}

scalar HexString


union Input = InputCoin | InputContract | InputMessage

type InputCoin {
	utxoId: UtxoId!
	owner: Address!
	amount: U64!
	assetId: AssetId!
	txPointer: TxPointer!
	witnessIndex: Int!
	maturity: U32!
	predicateGasUsed: U64!
	predicate: HexString!
	predicateData: HexString!
}

type InputContract {
	utxoId: UtxoId!
	balanceRoot: Bytes32!
	stateRoot: Bytes32!
	txPointer: TxPointer!
	contract: Contract!
}

type InputMessage {
	sender: Address!
	recipient: Address!
	amount: U64!
	nonce: Nonce!
	witnessIndex: Int!
	predicateGasUsed: U64!
	data: HexString!
	predicate: HexString!
	predicateData: HexString!
}


type MerkleProof {
	proofSet: [Bytes32!]!
	proofIndex: U64!
}

type Message {
	amount: U64!
	sender: Address!
	recipient: Address!
	nonce: Nonce!
	data: HexString!
	daHeight: U64!
}

type MessageCoin {
	sender: Address!
	recipient: Address!
	nonce: Nonce!
	amount: U64!
	assetId: AssetId!
	daHeight: U64!
}

type MessageConnection {
	"""
	Information to aid in pagination.
	"""
	pageInfo: PageInfo!
	"""
	A list of edges.
	"""
	edges: [MessageEdge!]!
	"""
	A list of nodes.
	"""
	nodes: [Message!]!
}

"""
An edge in a connection.
"""
type MessageEdge {
	"""
	A cursor for use in pagination
	"""
	cursor: String!
	"""
	The item at the end of the edge
	"""
	node: Message!
}

scalar MessageId

type MessageProof {
	messageProof: MerkleProof!
	blockProof: MerkleProof!
	messageBlockHeader: Header!
	commitBlockHeader: Header!
	sender: Address!
	recipient: Address!
	nonce: Nonce!
	amount: U64!
	data: HexString!
}

type Mutation {
	startSession: ID!
	endSession(id: ID!): Boolean!
	reset(id: ID!): Boolean!
	execute(id: ID!, op: String!): Boolean!
	setSingleStepping(id: ID!, enable: Boolean!): Boolean!
	setBreakpoint(id: ID!, breakpoint: Breakpoint!): Boolean!
	startTx(id: ID!, txJson: String!): RunResult!
	continueTx(id: ID!): RunResult!
	"""
	Execute a dry-run of the transaction using a fork of current state, no changes are committed.
	"""
	dryRun(tx: HexString!, utxoValidation: Boolean): [Receipt!]!
	"""
	Submits transaction to the `TxPool`.
	
	Returns submitted transaction if the transaction is included in the `TxPool` without problems.
	"""
	submit(tx: HexString!): Transaction!
	"""
	Sequentially produces `blocks_to_produce` blocks. The first block starts with
	`start_timestamp`. If the block production in the [`crate::service::Config`] is
	`Trigger::Interval { block_time }`, produces blocks with `block_time ` intervals between
	them. The `start_timestamp` is the timestamp in seconds.
	"""
	produceBlocks(startTimestamp: Tai64Timestamp, blocksToProduce: U64!): U32!
}

type NodeInfo {
	utxoValidation: Boolean!
	vmBacktrace: Boolean!
	minGasPrice: U64!
	maxTx: U64!
	maxDepth: U64!
	nodeVersion: String!
}

scalar Nonce

union Output = CoinOutput | ContractOutput | ChangeOutput | VariableOutput | ContractCreated

"""
A separate `Breakpoint` type to be used as an output, as a single
type cannot act as both input and output type in async-graphql
"""
type OutputBreakpoint {
	contract: ContractId!
	pc: U64!
}

"""
Information about pagination in a connection
"""
type PageInfo {
	"""
	When paginating backwards, are there more items?
	"""
	hasPreviousPage: Boolean!
	"""
	When paginating forwards, are there more items?
	"""
	hasNextPage: Boolean!
	"""
	When paginating backwards, the cursor to continue.
	"""
	startCursor: String
	"""
	When paginating forwards, the cursor to continue.
	"""
	endCursor: String
}

type PoAConsensus {
	"""
	Gets the signature of the block produced by `PoA` consensus.
	"""
	signature: Signature!
}

type ProgramState {
	returnType: ReturnType!
	data: HexString!
}

type Query {
	register(id: ID!, register: U64!): U64!
	memory(id: ID!, start: U64!, size: U64!): String!
	balance(owner: Address!, assetId: AssetId!): Balance!
	balances(filter: BalanceFilterInput!, first: Int, after: String, last: Int, before: String): BalanceConnection!
	block(id: BlockId, height: U64): Block
	blocks(first: Int, after: String, last: Int, before: String): BlockConnection!
	chain: ChainInfo!
	transaction(id: TransactionId!): Transaction
	transactions(first: Int, after: String, last: Int, before: String): TransactionConnection!
	transactionsByOwner(owner: Address!, first: Int, after: String, last: Int, before: String): TransactionConnection!
	"""
	Estimate the predicate gas for the provided transaction
	"""
	estimatePredicates(tx: HexString!): Transaction!
	"""
	Returns true when the GraphQL API is serving requests.
	"""
	health: Boolean!
	"""
	Gets the coin by `utxo_id`.
	"""
	coin(utxoId: UtxoId!): Coin
	"""
	Gets all unspent coins of some `owner` maybe filtered with by `asset_id` per page.
	"""
	coins(filter: CoinFilterInput!, first: Int, after: String, last: Int, before: String): CoinConnection!
	"""
	For each `query_per_asset`, get some spendable coins(of asset specified by the query) owned by
	`owner` that add up at least the query amount. The returned coins can be spent.
	The number of coins is optimized to prevent dust accumulation.
	
	The query supports excluding and maximum the number of coins.
	
	Returns:
	The list of spendable coins per asset from the query. The length of the result is
	the same as the length of `query_per_asset`. The ordering of assets and `query_per_asset`
	is the same.
	"""
	coinsToSpend(owner: Address!, queryPerAsset: [SpendQueryElementInput!]!, excludedIds: ExcludeInput): [[CoinType!]!]!
	contract(id: ContractId!): Contract
	contractBalance(contract: ContractId!, asset: AssetId!): ContractBalance!
	contractBalances(filter: ContractBalanceFilterInput!, first: Int, after: String, last: Int, before: String): ContractBalanceConnection!
	nodeInfo: NodeInfo!
	messages(owner: Address, first: Int, after: String, last: Int, before: String): MessageConnection!
	messageProof(transactionId: TransactionId!, messageId: MessageId!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof
}

type Receipt {
	contract: Contract
	pc: U64
	is: U64
	to: Contract
	toAddress: Address
	amount: U64
	assetId: AssetId
	gas: U64
	param1: U64
	param2: U64
	val: U64
	ptr: U64
	digest: Bytes32
	reason: U64
	ra: U64
	rb: U64
	rc: U64
	rd: U64
	len: U64
	receiptType: ReceiptType!
	rawPayload: HexString!
	result: U64
	gasUsed: U64
	data: HexString
	sender: Address
	recipient: Address
	nonce: Nonce
	contractId: ContractId
}

enum ReceiptType {
	CALL
	RETURN
	RETURN_DATA
	PANIC
	REVERT
	LOG
	LOG_DATA
	TRANSFER
	TRANSFER_OUT
	SCRIPT_RESULT
	MESSAGE_OUT
}

enum ReturnType {
	RETURN
	RETURN_DATA
	REVERT
}

type RunResult {
	state: RunState!
	breakpoint: OutputBreakpoint
	jsonReceipts: [String!]!
}

enum RunState {
	COMPLETED
	BREAKPOINT
}

scalar Salt

scalar Signature

input SpendQueryElementInput {
	"""
	Identifier of the asset to spend.
	"""
	assetId: AssetId!
	"""
	Target amount for the query.
	"""
	amount: U64!
	"""
	The maximum number of currencies for selection.
	"""
	max: U64
}

type SqueezedOutStatus {
	reason: String!
}


type SubmittedStatus {
	time: Tai64Timestamp!
}

type Subscription {
	"""
	Returns a stream of status updates for the given transaction id.
	If the current status is [`TransactionStatus::Success`], [`TransactionStatus::SqueezedOut`]
	or [`TransactionStatus::Failed`] the stream will return that and end immediately.
	If the current status is [`TransactionStatus::Submitted`] this will be returned
	and the stream will wait for a future update.
	
	This stream will wait forever so it's advised to use within a timeout.
	
	It is possible for the stream to miss an update if it is polled slower
	then the updates arrive. In such a case the stream will close without
	a status. If this occurs the stream can simply be restarted to return
	the latest status.
	"""
	statusChange(id: TransactionId!): TransactionStatus!
	"""
	Submits transaction to the `TxPool` and await either confirmation or failure.
	"""
	submitAndAwait(tx: HexString!): TransactionStatus!
}

type SuccessStatus {
	block: Block!
	time: Tai64Timestamp!
	programState: ProgramState
}

scalar Tai64Timestamp

type Transaction {
	id: TransactionId!
	inputAssetIds: [AssetId!]
	inputContracts: [Contract!]
	gasPrice: U64
	gasLimit: U64
	maturity: U32
	txPointer: TxPointer
	isScript: Boolean!
	isCreate: Boolean!
	isMint: Boolean!
	inputs: [Input!]
	outputs: [Output!]!
	witnesses: [HexString!]
	receiptsRoot: Bytes32
	status: TransactionStatus
	receipts: [Receipt!]
	script: HexString
	scriptData: HexString
	bytecodeWitnessIndex: Int
	bytecodeLength: U64
	salt: Salt
	storageSlots: [HexString!]
	"""
	Return the transaction bytes using canonical encoding
	"""
	rawPayload: HexString!
}

type TransactionConnection {
	"""
	Information to aid in pagination.
	"""
	pageInfo: PageInfo!
	"""
	A list of edges.
	"""
	edges: [TransactionEdge!]!
	"""
	A list of nodes.
	"""
	nodes: [Transaction!]!
}

"""
An edge in a connection.
"""
type TransactionEdge {
	"""
	A cursor for use in pagination
	"""
	cursor: String!
	"""
	The item at the end of the edge
	"""
	node: Transaction!
}

scalar TransactionId

union TransactionStatus = SubmittedStatus | SuccessStatus | SqueezedOutStatus | FailureStatus

scalar TxPointer

scalar U32

scalar U64

scalar UtxoId

type VariableOutput {
	to: Address!
	amount: U64!
	assetId: AssetId!
}

schema {
	query: Query
	mutation: Mutation
	subscription: Subscription
}
