Files
prime-sdk-go/models/models.go
Andrew Miller d945029f33 add GetInterchain: trace a transaction/block to validator blocks + interchain anchors
New Transaction.GetInterchain and Block.GetInterchain call the prime-node
/api/v1/{transaction,block}/{id}/interchain endpoints, returning an
InterchainTrace {blockId, validatorBlocks, interchainTransactions}. Adds local
VerificationBlock / InterchainTransaction / InterchainTrace model types.
2026-06-02 14:12:49 -04:00

209 lines
6.6 KiB
Go
Executable File

package models
const (
ContentTypeJSON = "application/json"
)
type TransactionCreateRequest struct {
Version string `json:"version,omitempty"`
TxnType string `json:"txn_type"`
Payload string `json:"payload"`
Tag string `json:"tag,omitempty"`
}
type TransactionCreateResponse struct {
TransactionID string `json:"transaction_id"`
}
type TransactionBulkRequest struct {
Transactions []TransactionCreateRequest `json:"transactions"`
}
type TransactionBulkResponse struct {
TransactionIDs []string `json:"transaction_ids"`
}
type TransactionListResponse struct {
TransactionTypes []*TransactionType `json:"transactionTypes"`
}
type Transaction struct {
Version string `json:"version"`
Header TransactionHeader `json:"header"`
Proof TransactionProof `json:"proof"`
Payload string `json:"payload"`
}
type TransactionHeader struct {
Tag string `json:"tag"`
DcId string `json:"dc_id"`
TxnId string `json:"txn_id"`
Invoker string `json:"invoker"`
BlockId string `json:"block_id"`
TxnType string `json:"txn_type"`
Timestamp string `json:"timestamp"`
}
type TransactionProof struct {
Full string `json:"full"`
Stripped string `json:"stripped"`
}
type ListTransactionsResponse struct {
Transactions []Transaction `json:"transactions"`
}
type TransactionTypeCreateRequest struct {
Version string `json:"version,omitempty"`
TxnType string `json:"txn_type"`
}
type TransactionTypeCreateResponse struct {
Success bool `json:"success"`
}
type TransactionType struct {
Version string `json:"version"`
Created int64 `json:"created"`
Modified int64 `json:"modified"`
TxnType string `json:"txn_type"`
ContractID string `json:"contract_id,omitempty"`
CustomIndexes []interface{} `json:"custom_indexes"`
ActiveSinceBlock string `json:"active_since_block"`
}
type SmartContractCreateRequest struct {
Environment string `json:"environment"`
TransactionType string `json:"transactionType"`
ExecutionOrder string `json:"executionOrder"`
EnvironmentVariables map[string]string `json:"environmentVariables,omitempty"`
Secrets map[string]string `json:"secret,omitempty"`
Remote bool `json:"remote,omitempty"`
}
type SmartContractUpdateRequest struct {
Version string `json:"version,omitempty"`
Enabled bool `json:"enabled"`
EnvironmentVariables map[string]string `json:"environmentVariables,omitempty"`
Secrets map[string]string `json:"secret,omitempty"`
}
type SmartContract struct {
Id string `json:"id"`
Created uint64 `json:"created"`
Modified uint64 `json:"modified"`
Version string `json:"version"`
Environment string `json:"environment"`
TransactionType string `json:"transactionType"`
ExecutionOrder string `json:"executionOrder"`
ExecutionInfo *SmartContractExecutionInfo `json:"executionInfo"`
EnvVars map[string]string `json:"envVars"`
Secrets []string `json:"secrets"`
GrpcConnectionInfo *GrpcConnectionInfo `json:"grpcConnectionInfo,omitempty"`
}
type GrpcConnectionInfo struct {
Address string `json:"address"`
ApiKey string `json:"apiKey,omitempty"`
}
type SmartContractExecutionInfo struct {
Type string `json:"type"`
// LocalExecutable type
ExecutablePath string `json:"executablePath"`
ExecutableWorkingDirectory string `json:"executableWorkingDirectory"`
ExecutableHash string `json:"executableHash"`
}
type Block struct {
Version string `json:"version"`
Header BlockHeader `json:"header"`
Transactions []string `json:"transactions"`
Proof BlockProof `json:"proof"`
}
type BlockHeader struct {
BlockId string `json:"blockId"`
DcId string `json:"dcId"`
PrevId string `json:"prevId"`
PrevProof string `json:"prevProof"`
Timestamp string `json:"timestamp"`
}
type BlockProof struct {
Proof string `json:"proof"`
Scheme string `json:"scheme,omitempty"`
Nonce int64 `json:"nonce,omitempty"`
}
type SystemStatus struct {
ID string `json:"id"`
Level int `json:"level"`
URL string `json:"url"`
HashAlgo string `json:"hashAlgo"`
Scheme string `json:"scheme"`
Version string `json:"version"`
EncryptionAlgo string `json:"encryptionAlgo"`
IndexingEnabled bool `json:"indexingEnabled"`
// Level 5 Node
Funded string `json:"funded,omitempty"`
BroadcastInterval string `json:"broadcastInterval,omitempty"`
Network string `json:"network,omitempty"`
InterchainWallet string `json:"interchainWallet,omitempty"`
}
type SuccessResponse struct {
Success bool `json:"success"`
}
type ErrorResponse struct {
Error string `json:"error"`
}
type ListResponse struct {
Items []interface{} `json:"items"`
TotalCount int `json:"total_count"`
}
// VerificationBlock is a validator's verification of a prime block.
type VerificationBlock struct {
Version string `json:"version"`
PrimeChainId string `json:"primeChainId"`
PrimeBlockId string `json:"primeBlockId"`
Timestamp string `json:"timestamp"`
VerifierPublicKey string `json:"verifierPublicKey"`
VerifierSignature string `json:"verifierSignature"`
}
// InterchainTransaction is an anchor broadcast to a public blockchain (e.g. ETH
// or BTC) that bundles one or more validator blocks. ValidatorBlocks holds the
// prime block ids covered; CoveredPrimeChainIds the prime chains they belong to.
type InterchainTransaction struct {
Id int `json:"id"`
Version string `json:"version"`
Timestamp string `json:"timestamp"`
ChainId string `json:"chainId"`
TransHash string `json:"transHash"`
BlockId string `json:"blockId"`
ValidatorBlocks []string `json:"validatorBlocks"`
ValidatorBlockhash string `json:"validatorBlockhash"`
Signature string `json:"signature"`
CoveredPrimeChainIds []string `json:"coveredPrimeChainIds"`
}
// InterchainTrace links a prime block to the validator (verification) blocks
// that validated it and the public-chain interchain anchors those validator
// blocks were bundled into. Returned by Transaction.GetInterchain and
// Block.GetInterchain.
type InterchainTrace struct {
BlockId string `json:"blockId"`
ValidatorBlocks []VerificationBlock `json:"validatorBlocks"`
InterchainTransactions []InterchainTransaction `json:"interchainTransactions"`
}