Commit 8f577bdc authored by vicotor's avatar vicotor

update proto

parent 0dc0cad7
package exchain
import "github.com/holiman/uint256"
type Wallet struct {
Coin string `json:"coin"`
Balance uint256.Int `json:"balance"`
FrozenBalance uint256.Int `json:"frozenBalance"`
}
func (w *Wallet) AddBalance(balance uint256.Int) {
w.Balance = *new(uint256.Int).Add(&w.Balance, &balance)
}
type ProxyPublickey [64]byte
type AccountInfo struct {
ProxySigner ProxyPublickey
Wallets []Wallet // a sorted wallet list.
}
func (acc *AccountInfo) GetWallet(coin string) *Wallet {
for i := range acc.Wallets {
if acc.Wallets[i].Coin == coin {
return &acc.Wallets[i]
}
}
return nil
}
func (acc *AccountInfo) GetWallets() []Wallet {
return acc.Wallets
}
// A wrapper for account defined in proto.
package exchain
// BackendService define all api that provide the info in server.
type BackendService interface {
// Get all pending orders info.
// Get all history orders info.
// Get all order books info.
}
// A wrapper for exchange service defined in proto.
......@@ -2,11 +2,21 @@ package exchain
import (
"github.com/ethereum/go-ethereum/common"
nebulav1 "github.com/exchain/go-exchain/exchain/protocol/gen/go/nebula/v1"
"github.com/holiman/uint256"
)
// This file define all database interfaces for exchain.
// Database is a simple key-value store.
type Database interface {
Get(key []byte) ([]byte, error)
Put(key []byte, value []byte) error
Delete(key []byte) error
}
type StateDB interface {
GetAccount(address common.Address) *AccountInfo
GetAccount(address common.Address) *nebulav1.Account
FrozenBalance(address common.Address, coin common.Address, balance uint256.Int) error
UnFrozenBalance(address common.Address, coin common.Address, balance uint256.Int) error
SubBalance(address common.Address, coin common.Address, balance uint256.Int) error
......
package exchain
import (
"context"
"github.com/exchain/go-exchain/op-service/eth"
"github.com/ethereum/go-ethereum/common"
nebulav1 "github.com/exchain/go-exchain/exchain/protocol/gen/go/nebula/v1"
)
// Engine define all api that op-node needed to build a block and process a block.
//
//// define the engine service
//service Engine {
//// NewPayload start to generate a new execution payload.
//rpc NewPayload(PayloadParams) returns (PayloadStatus) {}
//// GetPayload get the execution payload by the payload status.
//rpc GetPayload(PayloadStatus) returns (ExecutionPayload) {}
//
//// ProcessPayload execute a new execute payload that received from other node.
//rpc ProcessPayload(ExecutionPayload) returns (google.protobuf.Empty) {}
//}
//
//message PayloadStatus {
//string id = 1;
//}
//
//message PayloadParams {
//bytes parent_root = 1; // layer1 block hash.
//uint64 timestamp = 2;
//bytes proposer = 3;
//
//nebula.v1.TransactionList transactions = 4; // append to execute tx list.
//}
//
//message ExecutionPayload {
//uint64 height = 1;
//bytes hash = 2;
//bytes parent_hash = 3;
//uint64 timestamp = 4;
//bytes proposer = 5;
//bytes app_root = 6; // used to verify block is valid.
//nebula.v1.TransactionList transactions = 7;
//}
//
//message ExecutionResult {
//bytes parent_root = 1;
//ExecutionPayload payload = 2;
//}
type Signer func(data []byte) ([]byte, error)
type Engine interface {
// NewPayload generate a new execution payload.
NewPayload(ctx context.Context, params PayloadParams) (*ExecutionPayload, error)
// ProcessPayload execute a new execute payload that received from other node.
ProcessPayload(ctx context.Context, payload *ExecutionPayload) error
Start() error
NewPayload(params PayloadParams) (ExecutionResult, error)
ProcessPayload(block *nebulav1.Block) error
}
type PayloadParams struct {
ParentHash common.Hash
Timestamp eth.Uint64Quantity
Transactions []eth.Data
ParentRoot common.Hash
Timestamp uint64
Proposer common.Address
Transactions nebulav1.TransactionList
Signer Signer
}
type ExecutionResult struct {
ParentRoot common.Hash
Payload *nebulav1.Block
}
type mockEngine struct{}
func (m mockEngine) Start() error {
return nil
}
type ExecutionPayload struct {
ParentHash common.Hash `json:"parentHash"`
BlockHash common.Hash `json:"blockHash"`
BlockNumber eth.Uint64Quantity `json:"blockNumber"`
Timestamp eth.Uint64Quantity `json:"timestamp"`
func (m mockEngine) NewPayload(params PayloadParams) (ExecutionResult, error) {
return ExecutionResult{}, nil
}
func (m mockEngine) ProcessPayload(block *nebulav1.Block) error {
return nil
}
StateRoot eth.Bytes32 `json:"stateRoot"`
ReceiptsRoot eth.Bytes32 `json:"receiptsRoot"`
ExtraData eth.BytesMax32 `json:"extraData"`
Transactions []eth.Data `json:"transactions"`
func NewEngine(database Database) Engine {
return &mockEngine{}
}
......@@ -32,6 +32,8 @@ type BlockHeader struct {
ParentHash []byte `protobuf:"bytes,3,opt,name=parent_hash,json=parentHash,proto3" json:"parent_hash,omitempty"`
Timestamp uint64 `protobuf:"varint,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Proposer []byte `protobuf:"bytes,5,opt,name=proposer,proto3" json:"proposer,omitempty"`
AppRoot []byte `protobuf:"bytes,6,opt,name=app_root,json=appRoot,proto3" json:"app_root,omitempty"` // used to verify block is valid.
Signatures []byte `protobuf:"bytes,7,opt,name=signatures,proto3" json:"signatures,omitempty"` // used to verify block is mint by proposer.
}
func (x *BlockHeader) Reset() {
......@@ -101,6 +103,20 @@ func (x *BlockHeader) GetProposer() []byte {
return nil
}
func (x *BlockHeader) GetAppRoot() []byte {
if x != nil {
return x.AppRoot
}
return nil
}
func (x *BlockHeader) GetSignatures() []byte {
if x != nil {
return x.Signatures
}
return nil
}
type Block struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
......@@ -167,7 +183,7 @@ var file_nebula_v1_block_proto_rawDesc = []byte{
0x62, 0x75, 0x6c, 0x61, 0x2f, 0x65, 0x78, 0x74, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2f, 0x76,
0x31, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x22, 0x94, 0x01, 0x0a, 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61,
0x6f, 0x74, 0x6f, 0x22, 0xcf, 0x01, 0x0a, 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61,
0x64, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20,
0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x68,
0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12,
......@@ -176,30 +192,33 @@ var file_nebula_v1_block_proto_rawDesc = []byte{
0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x04, 0x20,
0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x1a,
0x0a, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c,
0x52, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x22, 0x87, 0x01, 0x0a, 0x05, 0x42,
0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x6e,
0x65, 0x62, 0x75, 0x6c, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65,
0x61, 0x64, 0x65, 0x72, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x46, 0x0a, 0x0c,
0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x22, 0x2e, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x6e, 0x65, 0x62,
0x75, 0x6c, 0x61, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69,
0x6f, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x42, 0xd3, 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x65, 0x78, 0x63,
0x68, 0x61, 0x69, 0x6e, 0x2e, 0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2e, 0x76, 0x31, 0x42, 0x0a,
0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x48, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e,
0x2f, 0x67, 0x6f, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2f, 0x65, 0x78, 0x63, 0x68,
0x61, 0x69, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x67, 0x65, 0x6e,
0x2f, 0x67, 0x6f, 0x2f, 0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2f, 0x76, 0x31, 0x3b, 0x6e, 0x65,
0x62, 0x75, 0x6c, 0x61, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x45, 0x4e, 0x58, 0xaa, 0x02, 0x11, 0x45,
0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2e, 0x56, 0x31,
0xca, 0x02, 0x11, 0x45, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5c, 0x4e, 0x65, 0x62, 0x75, 0x6c,
0x61, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1d, 0x45, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5c, 0x4e,
0x65, 0x62, 0x75, 0x6c, 0x61, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61,
0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x45, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x3a, 0x3a,
0x4e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
0x52, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x61, 0x70,
0x70, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x61, 0x70,
0x70, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75,
0x72, 0x65, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x73, 0x69, 0x67, 0x6e, 0x61,
0x74, 0x75, 0x72, 0x65, 0x73, 0x22, 0x87, 0x01, 0x0a, 0x05, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12,
0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1e, 0x2e, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61,
0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52,
0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x46, 0x0a, 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73,
0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e,
0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2e, 0x76,
0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42,
0xd3, 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e,
0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x42, 0x6c, 0x6f, 0x63, 0x6b,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x48, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2f, 0x67, 0x6f, 0x2d, 0x65,
0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2f, 0x65, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x6e,
0x65, 0x62, 0x75, 0x6c, 0x61, 0x2f, 0x76, 0x31, 0x3b, 0x6e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x76,
0x31, 0xa2, 0x02, 0x03, 0x45, 0x4e, 0x58, 0xaa, 0x02, 0x11, 0x45, 0x78, 0x63, 0x68, 0x61, 0x69,
0x6e, 0x2e, 0x4e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x11, 0x45, 0x78,
0x63, 0x68, 0x61, 0x69, 0x6e, 0x5c, 0x4e, 0x65, 0x62, 0x75, 0x6c, 0x61, 0x5c, 0x56, 0x31, 0xe2,
0x02, 0x1d, 0x45, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5c, 0x4e, 0x65, 0x62, 0x75, 0x6c, 0x61,
0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea,
0x02, 0x13, 0x45, 0x78, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x3a, 0x3a, 0x4e, 0x65, 0x62, 0x75, 0x6c,
0x61, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
......
This diff is collapsed.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc (unknown)
// source: node/v1/engine.proto
package nodev1
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// EngineClient is the client API for Engine service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type EngineClient interface {
// NewPayload generate a new execution payload.
NewPayload(ctx context.Context, in *PayloadParams, opts ...grpc.CallOption) (*ExecutionPayload, error)
// ProcessPayload execute a new execute payload that received from other node.
ProcessPayload(ctx context.Context, in *ExecutionPayload, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
type engineClient struct {
cc grpc.ClientConnInterface
}
func NewEngineClient(cc grpc.ClientConnInterface) EngineClient {
return &engineClient{cc}
}
func (c *engineClient) NewPayload(ctx context.Context, in *PayloadParams, opts ...grpc.CallOption) (*ExecutionPayload, error) {
out := new(ExecutionPayload)
err := c.cc.Invoke(ctx, "/exchain.node.v1.Engine/NewPayload", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *engineClient) ProcessPayload(ctx context.Context, in *ExecutionPayload, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/exchain.node.v1.Engine/ProcessPayload", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// EngineServer is the server API for Engine service.
// All implementations must embed UnimplementedEngineServer
// for forward compatibility
type EngineServer interface {
// NewPayload generate a new execution payload.
NewPayload(context.Context, *PayloadParams) (*ExecutionPayload, error)
// ProcessPayload execute a new execute payload that received from other node.
ProcessPayload(context.Context, *ExecutionPayload) (*emptypb.Empty, error)
mustEmbedUnimplementedEngineServer()
}
// UnimplementedEngineServer must be embedded to have forward compatible implementations.
type UnimplementedEngineServer struct {
}
func (UnimplementedEngineServer) NewPayload(context.Context, *PayloadParams) (*ExecutionPayload, error) {
return nil, status.Errorf(codes.Unimplemented, "method NewPayload not implemented")
}
func (UnimplementedEngineServer) ProcessPayload(context.Context, *ExecutionPayload) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method ProcessPayload not implemented")
}
func (UnimplementedEngineServer) mustEmbedUnimplementedEngineServer() {}
// UnsafeEngineServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to EngineServer will
// result in compilation errors.
type UnsafeEngineServer interface {
mustEmbedUnimplementedEngineServer()
}
func RegisterEngineServer(s grpc.ServiceRegistrar, srv EngineServer) {
s.RegisterService(&Engine_ServiceDesc, srv)
}
func _Engine_NewPayload_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PayloadParams)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(EngineServer).NewPayload(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/exchain.node.v1.Engine/NewPayload",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EngineServer).NewPayload(ctx, req.(*PayloadParams))
}
return interceptor(ctx, in, info, handler)
}
func _Engine_ProcessPayload_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ExecutionPayload)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(EngineServer).ProcessPayload(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/exchain.node.v1.Engine/ProcessPayload",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EngineServer).ProcessPayload(ctx, req.(*ExecutionPayload))
}
return interceptor(ctx, in, info, handler)
}
// Engine_ServiceDesc is the grpc.ServiceDesc for Engine service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Engine_ServiceDesc = grpc.ServiceDesc{
ServiceName: "exchain.node.v1.Engine",
HandlerType: (*EngineServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "NewPayload",
Handler: _Engine_NewPayload_Handler,
},
{
MethodName: "ProcessPayload",
Handler: _Engine_ProcessPayload_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "node/v1/engine.proto",
}
......@@ -19,6 +19,8 @@ message BlockHeader {
bytes parent_hash = 3;
uint64 timestamp = 4;
bytes proposer = 5;
bytes app_root = 6; // used to verify block is valid.
bytes signatures = 7; // used to verify block is mint by proposer.
}
message Block {
......
......@@ -13,20 +13,25 @@ option java_outer_classname = "ReceiptProto";
option java_package = "org.exchain.nebula.v1";
option php_namespace = "ExChain\\Nebula\\v1";
message TransactionReceiptList {
repeated TransactionReceipt receipts = 1;
}
message TransactionReceipt {
bytes hash = 1;
TxType tx_type = 2;
bool success = 3;
bytes block_hash = 4;
uint64 block_height = 4;
uint64 timestamp = 5;
oneof content {
SignProxyReceipt sign_proxy_r = 5;
DepositReceipt deposit_r = 6;
WithdrawReceipt withdraw_r = 7;
CreatePairReceipt create_pair_r = 8;
DisablePairReceipt disable_pair_r = 9;
LimitOrderReceipt limit_r = 10;
MarketOrderReceipt market_r = 11;
CancelOrderReceipt cancel_r = 12;
SignProxyReceipt sign_proxy_r = 6;
DepositReceipt deposit_r = 7;
WithdrawReceipt withdraw_r = 8;
CreatePairReceipt create_pair_r = 9;
DisablePairReceipt disable_pair_r = 10;
LimitOrderReceipt limit_r = 11;
MarketOrderReceipt market_r = 12;
CancelOrderReceipt cancel_r = 13;
}
}
......
syntax = "proto3";
package exchain.node.v1;
import "google/protobuf/descriptor.proto";
import "google/protobuf/empty.proto";
option csharp_namespace = "ExChain.Node.V1";
option go_package = "github.com/exchain/go-exchain/exchain/protocol/node/v1";
option java_multiple_files = true;
option java_outer_classname = "EngineProto";
option java_package = "org.exchain.node.v1";
option php_namespace = "ExChain\\Node\\v1";
// define the engine service
service Engine {
// NewPayload generate a new execution payload.
rpc NewPayload(PayloadParams) returns (ExecutionPayload) {}
// ProcessPayload execute a new execute payload that received from other node.
rpc ProcessPayload(ExecutionPayload) returns (google.protobuf.Empty) {}
}
message PayloadParams {
bytes parent_hash = 1;
uint64 timestamp = 2;
repeated bytes transactions = 3;
}
message ExecutionPayload {
bytes parent_hash = 1;
bytes block_hash = 2;
uint64 block_number = 3;
uint64 timestamp = 4;
bytes state_root = 5;
bytes receipts_root = 6;
bytes extra_data = 7;
repeated bytes transactions = 8;
}
package exchain
import (
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
)
// ChainRPC define all rpc that provide the info on chain.
type ChainRPC interface {
// Account Reference
GetAccount(address common.Address) AccountInfo
// Block Reference
GetHeaderByNumber(number *uint256.Int)
GetBlockByNumber(number *uint256.Int)
GetBlockByHash(hash common.Hash)
// Tx Reference
SendRawTransaction(tx []byte) (common.Hash, error)
GetTransactionByHash(hash common.Hash) (Transaction, error)
GetTransactionReceipt(hash common.Hash) (TransactionReceipt, error)
}
package exchain
import (
"encoding/json"
"github.com/exchain/go-exchain/op-service/eth"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
"math/big"
)
type TxType string
const (
SignProxyTx TxType = "sign_proxy" // update a signer proxy public key.
DepositTx TxType = "deposit" // deposit usdt/usdc from l1 to exchain.
WithdrawTx TxType = "withdraw" // withdraw usdt/usdc from exchain to l1.
CreateOrderBookTx TxType = "create_order_book" // create a new orderbook.
DisableOrderBookTx TxType = "disable_order_book" // disable an existing orderbook.
LimitTx TxType = "limit" // make a limit order.
MarketTx TxType = "market" // make a market order.
CancelTx TxType = "cancel" // cancel an order.
)
type Signature struct {
R *uint256.Int
S *uint256.Int
V byte
}
type Transaction struct {
User common.Address `json:"user"`
Nonce uint256.Int `json:"nonce"`
Type TxType `json:"type"`
Proxy bool `json:"proxy"`
Data json.RawMessage `json:"data"`
Signature Signature `json:"signature"`
}
type TransactionReceipt struct {
Hash common.Hash `json:"hash"`
TxType TxType `json:"txType"`
Status uint8 `json:"status"`
BlockHash common.Hash `json:"blockHash"`
Content []eth.Data `json:"content"` // content is difference by txType.
}
type DepositTxData struct {
// SourceHash uniquely identifies the source of the deposit
SourceHash common.Hash
// From is exposed through the types.Signer, not through TxData
From common.Address
// nil means contract creation
To *common.Address
// Mint is minted on L2, locked on L1, nil if no minting.
Mint *big.Int
// Value is transferred from L2 balance, executed after Mint (if any)
Value *big.Int
// Field indicating if this transaction is exempt from the L2 gas limit.
IsSystemTransaction bool
// Normal Tx data
Data []byte
}
type LimitTxData struct {
Symbol string `json:"symbol"`
Side uint8 `json:"side"`
Price uint256.Int `json:"price"`
Quantity uint256.Int `json:"quantity"`
}
type MarketTxData struct {
Symbol string `json:"symbol"`
Side uint8 `json:"side"`
Quantity uint256.Int `json:"quantity"`
}
func (tx Transaction) SigHash() common.Hash {
data := make([]byte, 0)
data = append(data, tx.User.Bytes()...)
data = append(data, tx.Nonce.Bytes()...)
data = append(data, tx.Type...)
if tx.Proxy {
data = append(data, byte(1))
} else {
data = append(data, byte(0))
}
txdata, _ := json.Marshal(tx.Data)
data = append(data, txdata...)
return crypto.Keccak256Hash(data)
}
func (tx Transaction) Verify() bool {
return true
//if tx.Proxy {
// // get user proxy public.
// var public ProxyPublickey
// pubkey, err := crypto.UnmarshalPubkey(public[:])
// if err != nil {
// return false
// } else {
// crypto.VerifySignature()
// }
//
//}
}
// A wrapper for transaction defined in proto.
package exchain
import (
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
)
type BlockHeader struct {
Height uint256.Int
Hash common.Hash
Parent common.Hash
Timestamp uint64
Proposer common.Address
}
type Coin struct{}
type ExPair struct{}
// todo: define some structs here.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment