syntax = "proto3";

option csharp_namespace = "AElf.Kernel";

import "google/protobuf/timestamp.proto";
import "common.proto";
import "crosschain.proto";

message Transaction {
    Address From = 1;
    Address To = 2;
    uint64 RefBlockNumber = 3;
    bytes RefBlockPrefix = 4;
    uint64 IncrementId = 5;
    string MethodName = 6;
    bytes Params = 7;
    uint64 Fee = 8;
    repeated bytes Sigs = 9;
    TransactionType Type = 10;
    google.protobuf.Timestamp Time = 11;
}

message TransactionReceipt {
    enum TransactionStatus {
        UnknownTransactionStatus = 0;
        TransactionExecuting = 1;
        TransactionExecuted = 2;
    }
    enum SignatureStatus {
        UnknownSignatureStatus = 0;
        SignatureValid = 1;
        SignatureInvalid = -1;
    }
    enum RefBlockStatus {
        UnknownRefBlockStatus = 0;
        RefBlockValid = 1;
        RefBlockInvalid = -1;
        RefBlockExpired = -2;
        FutureRefBlock = -3;
    }
    Hash TransactionId = 1;
    Transaction Transaction = 2;
    SignatureStatus SignatureSt = 3;
    RefBlockStatus RefBlockSt = 4;
    TransactionStatus Status = 5;
    bool IsSystemTxn = 6;
    uint64 ExecutedBlockNumber = 7;
}

message StatePath {
    repeated bytes Path = 1;
    //    Address ContractAddress = 2;
    //    Hash ChainId = 3;
}

message StateValue {
    bytes CurrentValue = 1;
    bytes OriginalValue = 2;
}

message StateChange {
    StatePath StatePath = 1;
    StateValue StateValue = 2;
}

message TransactionList {
    repeated Transaction Transactions = 1;
}

enum TransactionType {
    ContractTransaction = 0;
    DposTransaction = 1;
    MsigTransaction = 2;
    ContractDeployTransaction=3;
}

enum Status {
    NotExisted = 0;
    Pending = 1;
    Failed = 2;
    Mined = 3;
}

message TransactionResult {
    Hash TransactionId = 1;
    Status Status = 2;
    repeated LogEvent Logs = 3;
    bytes Bloom = 4;
    bytes RetVal = 5;
    uint64 BlockNumber = 6;
    Hash BlockHash = 7;
    int32 Index = 8;
    Hash StateHash = 9;
    // Merkle proof path for this transaction
    Hash DeferredTxnId = 10;
}

// For failed transactions, its status follows the Min of
// its own status and its inline transactions'
enum ExecutionStatus {
    Undefined = 0;
    // Successful =>
    ExecutedButNotCommitted = 1;
    ExecutedAndCommitted = 2;

    // Failed =>
    //   Infrastructure reasons
    Canceled = -1;
    SystemError = -2;

    //   Contract reasons
    ContractError = -10;
    ExceededMaxCallDepth = -11;
}

message TransactionTrace {
    Hash TransactionId = 1;
    RetVal RetVal = 2;
    string StdOut = 3;
    string StdErr = 4;
    Hash StateHash = 5;
    repeated LogEvent Logs = 6;
    repeated Transaction InlineTransactions = 7;
    repeated TransactionTrace InlineTraces = 8;
    repeated StateChange StateChanges = 9;
    int64 Elapsed = 10;
    ExecutionStatus ExecutionStatus = 11;
    bytes DeferredTransaction = 12;
}

message LogEvent {
    Address Address = 1;
    repeated bytes Topics = 2;
    bytes Data = 3;
}

message RetVal {
    RetType Type = 1;
    bytes Data = 2;
    enum RetType {
        Void = 0;
        Bool = 1;
        Int32 = 2;
        UInt32 = 3;
        Int64 = 4;
        UInt64 = 5;
        String = 6;
        Bytes = 7;
        PbMessage = 8;
        UserType = 9;
    }
}

message BlockHeaderList {
    repeated BlockHeader Headers = 1;
}

message BlockHeader {
    int32 Version = 1;
    Hash PreviousBlockHash = 2;
    Hash MerkleTreeRootOfTransactions = 3;
    Hash MerkleTreeRootOfWorldState = 4;
    bytes Bloom = 5;
    uint64 Index = 6;
    bytes Sig = 7;
    bytes P = 8;
    google.protobuf.Timestamp Time = 9;
    Hash ChainId = 10;
    Hash SideChainTransactionsRoot = 11;
}

message BlockBody {
    Hash BlockHeader = 1;
    repeated Hash Transactions = 2;
    repeated Transaction TransactionList = 3;
    repeated SideChainBlockInfo IndexedInfo = 4;
}

message Block {
    BlockHeader Header = 1;
    BlockBody Body = 2;
}

message SmartContractRegistration {
    int32 Category = 1;
    Hash ContractHash = 2;
    bytes ContractBytes = 3;
    uint64 SerialNumber=4;
}

message SmartContractDeployment {
    Hash ContractHash = 1;
    Hash Caller = 2;
    bytes ConstructParams = 3;
    uint64 IncrementId = 4;
}

message Parameters {
    repeated Param Params = 1;
}

message Param {
    oneof data {
        int32 intVal = 1;
        uint32 uintVal = 2;
        int64 longVal = 3;
        uint64 ulongVal = 4;
        bool boolVal = 5;
        bytes bytesVal = 6;
        string strVal = 7;
        double dVal = 8; // Maybe don't allow floating point
        Hash hashVal = 9;
        SmartContractRegistration registerVal = 10;
        SmartContractDeployment deploymentVal = 11;
    }
}

message SmartContractInvokeContext {
    Hash Caller = 1;
    uint64 IncrementId = 2;
    string MethodName = 3;
    bytes Params = 4;
}

message DataItem {
    Hash ResourcePath = 1;
    Hash ResourcePointer = 2;
    Hash StateMerkleTreeLeaf = 3;
}

message WorldState {
    repeated DataItem Data = 1;
}

message Chain {
    Hash Id = 1;
    Hash GenesisBlockHash = 2;
}

enum DataAccessMode {
    ReadOnlyAccountSharing = 0;
    ReadWriteAccountSharing = 1;
    AccountSpecific = 2;
}

message Key {
    bytes Value = 1;
    string type = 2;
    uint32 HashType = 3;
}

message DataPath {
    Hash ChainId = 1;
    uint64 BlockHeight = 2;
    Address BlockProducerAddress = 3;
    Address ContractAddress = 4;
    Hash DataProviderHash = 5;
    Hash KeyHash = 6;
    StatePath StatePath = 7;
}

message BinaryMerkleTree{
    repeated Hash Nodes = 1;
    Hash Root = 2;
    int32 LeafCount = 3;
}

message StringList {
    repeated string Values = 1;
}