Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
process
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
process
Commits
eb086344
Commit
eb086344
authored
Apr 06, 2025
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
db3fa0df
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
586 additions
and
297 deletions
+586
-297
.gitignore
.gitignore
+1
-1
Makefile
Makefile
+1
-1
gateway.go
api/gateway/gateway.go
+168
-0
order_handler.go
api/handlers/order_handler.go
+0
-167
router.go
api/router/router.go
+0
-25
order.go
api/types/order.go
+15
-8
main.go
cmd/gateway/main.go
+12
-0
agent.go
engine/agent.go
+16
-1
engine.go
engine/engine.go
+19
-5
order.go
engine/order.go
+77
-11
process.go
engine/process.go
+101
-0
go.mod
go.mod
+28
-24
go.sum
go.sum
+117
-54
transaction.go
types/transaction.go
+19
-0
signature.go
utils/signature.go
+12
-0
No files found.
.gitignore
View file @
eb086344
.vscode
.idea
build
\ No newline at end of file
build
Makefile
View file @
eb086344
...
...
@@ -5,4 +5,4 @@ GOBIN = $(shell pwd)/build
default
:
api
api
:
go build
$(BUILD_FLAGS)
-v
-o
=
${
GOBIN
}
/
$@
./cmd/api
\ No newline at end of file
go build
$(BUILD_FLAGS)
-v
-o
=
${
GOBIN
}
/
$@
./cmd/gateway
\ No newline at end of file
api/gateway/gateway.go
0 → 100644
View file @
eb086344
package
apigateway
import
(
"context"
"encoding/json"
"fmt"
"math/big"
"net"
"net/http"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
nebulav1
"github.com/exchain/go-exchain/exchain/protocol/gen/go/nebula/v1"
orderbookv1
"github.com/exchain/go-exchain/exchain/protocol/gen/go/orderbook/v1"
"github.com/exchain/process/engine"
"github.com/exchain/process/orderbook"
"github.com/exchain/process/types"
"github.com/exchain/process/utils"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/holiman/uint256"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
type
server
struct
{
eg
*
engine
.
Engine
orderbookv1
.
UnimplementedOrderbookServer
}
func
(
s
*
server
)
PlaceLimitOrder
(
ctx
context
.
Context
,
req
*
orderbookv1
.
PlaceLimitOrderRequest
)
(
resp
*
orderbookv1
.
Response
,
err
error
)
{
resp
=
new
(
orderbookv1
.
Response
)
side
:=
orderbook
.
Buy
tx
:=
req
.
Transaction
.
Tx
.
(
*
nebulav1
.
Transaction_LimitTx
)
if
tx
.
LimitTx
.
Side
==
nebulav1
.
OrderSide_SELL
{
side
=
orderbook
.
Sell
}
coins
:=
strings
.
Split
(
tx
.
LimitTx
.
Pair
,
"-"
)
baseCoin
,
quoteCoin
:=
coins
[
0
],
coins
[
1
]
quantity
:=
new
(
uint256
.
Int
)
.
SetBytes
(
tx
.
LimitTx
.
Quantity
)
price
:=
new
(
uint256
.
Int
)
.
SetBytes
(
tx
.
LimitTx
.
Price
)
nonce
:=
new
(
big
.
Int
)
.
SetBytes
(
req
.
Transaction
.
Nonce
)
orderID
:=
utils
.
GenOrderID
()
_
,
res
,
err
:=
s
.
eg
.
ProcessLimitOrder
(
orderID
,
types
.
Coin
(
baseCoin
),
types
.
Coin
(
quoteCoin
),
common
.
HexToAddress
(
req
.
Transaction
.
User
),
side
,
price
,
quantity
,
uint64
(
nonce
.
Int64
()),
req
.
Transaction
.
Proxy
,
utils
.
CombineRSV
(
req
.
Transaction
.
Signature
.
R
,
req
.
Transaction
.
Signature
.
S
,
uint8
(
req
.
Transaction
.
Signature
.
V
)))
if
err
!=
nil
{
return
}
data
,
_
:=
json
.
Marshal
(
res
)
return
&
orderbookv1
.
Response
{
Data
:
data
},
nil
}
func
(
s
*
server
)
PlaceMarketOrder
(
ctx
context
.
Context
,
req
*
orderbookv1
.
PlaceMarketOrderRequest
)
(
resp
*
orderbookv1
.
Response
,
err
error
)
{
resp
=
new
(
orderbookv1
.
Response
)
side
:=
orderbook
.
Buy
tx
:=
req
.
Transaction
.
Tx
.
(
*
nebulav1
.
Transaction_MarketTx
)
if
tx
.
MarketTx
.
Side
==
nebulav1
.
OrderSide_SELL
{
side
=
orderbook
.
Sell
}
coins
:=
strings
.
Split
(
tx
.
MarketTx
.
Pair
,
"-"
)
baseCoin
,
quoteCoin
:=
coins
[
0
],
coins
[
1
]
quantity
:=
new
(
uint256
.
Int
)
.
SetBytes
(
tx
.
MarketTx
.
Quantity
)
nonce
:=
new
(
big
.
Int
)
.
SetBytes
(
req
.
Transaction
.
Nonce
)
orderID
:=
utils
.
GenOrderID
()
_
,
res
,
err
:=
s
.
eg
.
ProcessMarketOrder
(
orderID
,
types
.
Coin
(
baseCoin
),
types
.
Coin
(
quoteCoin
),
common
.
HexToAddress
(
req
.
Transaction
.
User
),
side
,
quantity
,
uint64
(
nonce
.
Int64
()),
req
.
Transaction
.
Proxy
,
utils
.
CombineRSV
(
req
.
Transaction
.
Signature
.
R
,
req
.
Transaction
.
Signature
.
S
,
uint8
(
req
.
Transaction
.
Signature
.
V
)))
if
err
!=
nil
{
return
}
data
,
_
:=
json
.
Marshal
(
res
)
return
&
orderbookv1
.
Response
{
Data
:
data
},
nil
}
func
(
s
*
server
)
CancelOrder
(
ctx
context
.
Context
,
req
*
orderbookv1
.
CancelOrderRequest
)
(
resp
*
orderbookv1
.
Response
,
err
error
)
{
tx
:=
req
.
Transaction
.
Tx
.
(
*
nebulav1
.
Transaction_CancelTx
)
orderID
:=
tx
.
CancelTx
.
OrderId
coins
:=
strings
.
Split
(
tx
.
CancelTx
.
Pair
,
"-"
)
baseCoin
,
quoteCoin
:=
coins
[
0
],
coins
[
1
]
nonce
:=
new
(
big
.
Int
)
.
SetBytes
(
req
.
Transaction
.
Nonce
)
err
=
s
.
eg
.
ProcessCancelOrder
(
orderID
,
types
.
Coin
(
baseCoin
),
types
.
Coin
(
quoteCoin
),
common
.
HexToAddress
(
req
.
Transaction
.
User
),
nonce
.
Uint64
(),
req
.
Transaction
.
Proxy
,
utils
.
CombineRSV
(
req
.
Transaction
.
Signature
.
R
,
req
.
Transaction
.
Signature
.
S
,
uint8
(
req
.
Transaction
.
Signature
.
V
)))
return
&
orderbookv1
.
Response
{},
err
}
func
(
s
*
server
)
SignProxy
(
ctx
context
.
Context
,
req
*
orderbookv1
.
SignProxyRequest
)
(
resp
*
orderbookv1
.
Response
,
err
error
)
{
tx
:=
req
.
Transaction
.
Tx
.
(
*
nebulav1
.
Transaction_SignProxyTx
)
nonce
:=
new
(
big
.
Int
)
.
SetBytes
(
req
.
Transaction
.
Nonce
)
pubkey
,
err
:=
crypto
.
UnmarshalPubkey
(
tx
.
SignProxyTx
.
SignerProxy
)
if
err
!=
nil
{
return
}
err
=
s
.
eg
.
PorcessSignProxy
(
common
.
HexToAddress
(
req
.
Transaction
.
User
),
crypto
.
PubkeyToAddress
(
*
pubkey
),
nonce
.
Uint64
(),
utils
.
CombineRSV
(
req
.
Transaction
.
Signature
.
R
,
req
.
Transaction
.
Signature
.
S
,
uint8
(
req
.
Transaction
.
Signature
.
V
)))
return
&
orderbookv1
.
Response
{},
err
}
func
StartServer
(
grpcPort
int
,
gwPort
int
,
eg
*
engine
.
Engine
)
error
{
defer
log
.
Info
(
"grpc and gateway server stopped"
)
log
.
Info
(
"starting grpc and gateway server"
,
"grpcPort"
,
grpcPort
,
"gwPort"
,
gwPort
)
ctx
:=
context
.
Background
()
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
gServer
:=
&
server
{
eg
:
eg
,
}
listener
,
err
:=
net
.
Listen
(
"tcp"
,
fmt
.
Sprintf
(
"0.0.0.0:%d"
,
grpcPort
))
if
err
!=
nil
{
log
.
Error
(
"failed to listen"
,
"err"
,
err
)
return
err
}
errCh
:=
make
(
chan
error
)
grpcServer
:=
grpc
.
NewServer
()
orderbookv1
.
RegisterOrderbookServer
(
grpcServer
,
gServer
)
go
func
(
ch
chan
error
)
{
var
e
=
grpcServer
.
Serve
(
listener
)
ch
<-
e
}(
errCh
)
mux
:=
runtime
.
NewServeMux
()
opts
:=
[]
grpc
.
DialOption
{
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
())}
err
=
orderbookv1
.
RegisterOrderbookHandlerFromEndpoint
(
ctx
,
mux
,
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
grpcPort
),
opts
)
if
err
!=
nil
{
return
err
}
go
func
(
ch
chan
error
)
{
var
e
=
http
.
ListenAndServe
(
fmt
.
Sprintf
(
"0.0.0.0:%d"
,
gwPort
),
mux
)
ch
<-
e
}(
errCh
)
e
:=
<-
errCh
return
e
}
api/handlers/order_handler.go
deleted
100644 → 0
View file @
db3fa0df
package
handlers
import
(
"net/http"
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
"github.com/gin-gonic/gin"
apiTypes
"github.com/exchain/process/api/types"
"github.com/exchain/process/engine"
"github.com/exchain/process/orderbook"
"github.com/exchain/process/types"
"github.com/exchain/process/utils"
)
type
OrderHandler
struct
{
eg
*
engine
.
Engine
}
func
NewOrderHandler
(
eg
*
engine
.
Engine
)
*
OrderHandler
{
return
&
OrderHandler
{
eg
:
eg
,
}
}
// PlaceLimitOrder 处理限价单请求
func
(
h
*
OrderHandler
)
PlaceLimitOrder
(
c
*
gin
.
Context
)
{
var
req
apiTypes
.
PlaceLimitOrderRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
ok
,
agent
:=
req
.
Recover
()
if
!
ok
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid signature"
})
return
}
side
:=
orderbook
.
Buy
if
req
.
Side
==
"sell"
{
side
=
orderbook
.
Sell
}
quantity
,
err
:=
uint256
.
FromDecimal
(
req
.
Quantity
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid quantity"
})
return
}
price
,
err
:=
uint256
.
FromDecimal
(
req
.
Price
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid price"
})
return
}
orderID
:=
utils
.
GenOrderID
()
_
,
resp
,
err
:=
h
.
eg
.
ProcessLimitOrder
(
orderID
,
types
.
Coin
(
req
.
BaseToken
),
types
.
Coin
(
req
.
QuoteToken
),
agent
,
side
,
price
,
quantity
,
req
.
Nonce
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
}
// PlaceMarketOrder 处理市价单请求
func
(
h
*
OrderHandler
)
PlaceMarketOrder
(
c
*
gin
.
Context
)
{
var
req
apiTypes
.
PlaceMarketOrderRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
ok
,
agent
:=
req
.
Recover
()
if
!
ok
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid signature"
})
return
}
side
:=
orderbook
.
Sell
if
req
.
Side
==
"buy"
{
side
=
orderbook
.
Buy
}
quantity
,
err
:=
uint256
.
FromDecimal
(
req
.
Quantity
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid quantity"
})
return
}
orderID
:=
utils
.
GenOrderID
()
_
,
resp
,
err
:=
h
.
eg
.
ProcessMarketOrder
(
orderID
,
types
.
Coin
(
req
.
BaseToken
),
types
.
Coin
(
req
.
QuoteToken
),
agent
,
side
,
quantity
,
req
.
Nonce
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
c
.
JSON
(
http
.
StatusOK
,
resp
)
}
// GetOrderBook 获取订单簿深度
func
(
h
*
OrderHandler
)
GetOrderBookDepth
(
c
*
gin
.
Context
)
{
var
req
apiTypes
.
DepthRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
asks
,
bids
,
err
:=
h
.
eg
.
Depth
(
types
.
Coin
(
req
.
BaseToken
),
types
.
Coin
(
req
.
QuoteToken
))
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"asks"
:
asks
,
"bids"
:
bids
,
})
}
// CancelOrder 取消订单
func
(
h
*
OrderHandler
)
CancelOrder
(
c
*
gin
.
Context
)
{
var
req
apiTypes
.
CancelOrderRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
ok
,
agent
:=
req
.
Recover
()
if
!
ok
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid signature"
})
return
}
err
:=
h
.
eg
.
ProcessCancelOrder
(
req
.
OrderId
,
types
.
Coin
(
req
.
BaseToken
),
types
.
Coin
(
req
.
QuoteToken
),
agent
,
req
.
Nonce
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"message"
:
"success"
,
})
}
func
(
h
*
OrderHandler
)
SignProxy
(
c
*
gin
.
Context
)
{
var
req
apiTypes
.
SignProxyRequest
if
err
:=
c
.
ShouldBindJSON
(
&
req
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
ok
,
user
:=
req
.
Recover
()
if
!
ok
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid signature"
})
return
}
err
:=
h
.
eg
.
PorcessSignProxy
(
user
,
common
.
HexToAddress
(
req
.
Agent
),
req
.
Nonce
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"message"
:
"success"
,
})
}
api/router/router.go
deleted
100644 → 0
View file @
db3fa0df
package
router
import
(
"github.com/exchain/process/api/handlers"
"github.com/gin-gonic/gin"
)
// SetupRouter 配置API路由
func
SetupRouter
(
orderHandler
*
handlers
.
OrderHandler
)
*
gin
.
Engine
{
r
:=
gin
.
Default
()
// 订单相关路由
orderGroup
:=
r
.
Group
(
"/api/v1/orders"
)
{
orderGroup
.
POST
(
"/limit"
,
orderHandler
.
PlaceLimitOrder
)
// 限价单
orderGroup
.
POST
(
"/market"
,
orderHandler
.
PlaceMarketOrder
)
// 市价单
orderGroup
.
POST
(
"/cancel"
,
orderHandler
.
CancelOrder
)
// 取消订单
}
// 订单簿相关路由
r
.
GET
(
"/api/v1/orderbook"
,
orderHandler
.
GetOrderBookDepth
)
// 获取订单簿深度
return
r
}
api/types/order.go
View file @
eb086344
...
...
@@ -17,14 +17,16 @@ type PlaceLimitOrderRequest struct {
Quantity
string
`json:"quantity" binding:"required"`
Price
string
`json:"price" binding:"required"`
Nonce
uint64
`json:"nonce" binding:"required"`
V
int32
`json:"v" binding:"required"`
Proxy
*
bool
`json:"proxy" binding:"required"`
V
uint8
`json:"v" binding:"required"`
R
hexutil
.
Bytes
`json:"r" binding:"required"`
S
hexutil
.
Bytes
`json:"s" binding:"required"`
}
func
(
r
*
PlaceLimitOrderRequest
)
Recover
()
(
ok
bool
,
address
common
.
Address
)
{
data
:=
fmt
.
Sprintf
(
"baseToken=%s"eToken=%s&side=%s&quantity=%s&price=%s&nonce=%d"
,
r
.
BaseToken
,
r
.
QuoteToken
,
r
.
Side
,
r
.
Quantity
,
r
.
Price
,
r
.
Nonce
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
data
))
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
// combile sig
sig
:=
make
([]
byte
,
65
)
copy
(
sig
,
r
.
R
)
...
...
@@ -45,14 +47,16 @@ type PlaceMarketOrderRequest struct {
Side
string
`json:"side" binding:"required,oneof=buy sell"`
Quantity
string
`json:"quantity" binding:"required"`
Nonce
uint64
`json:"nonce" binding:"required"`
V
int32
`json:"v" binding:"required"`
Proxy
*
bool
`json:"proxy" binding:"required"`
V
uint8
`json:"v" binding:"required"`
R
hexutil
.
Bytes
`json:"r" binding:"required"`
S
hexutil
.
Bytes
`json:"s" binding:"required"`
}
func
(
r
*
PlaceMarketOrderRequest
)
Recover
()
(
ok
bool
,
address
common
.
Address
)
{
data
:=
fmt
.
Sprintf
(
"baseToken=%s"eToken=%s&side=%s&quantity=%s&nonce=%d"
,
r
.
BaseToken
,
r
.
QuoteToken
,
r
.
Side
,
r
.
Quantity
,
r
.
Nonce
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
data
))
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
// combile sig
sig
:=
make
([]
byte
,
65
)
copy
(
sig
,
r
.
R
)
...
...
@@ -75,14 +79,16 @@ type CancelOrderRequest struct {
QuoteToken
string
`json:"quoteToken" binding:"required"`
OrderId
string
`json:"orderId" binding:"required"`
Nonce
uint64
`json:"nonce" binding:"required"`
V
int32
`json:"v" binding:"required"`
Proxy
*
bool
`json:"proxy" binding:"required"`
V
uint8
`json:"v" binding:"required"`
R
hexutil
.
Bytes
`json:"r" binding:"required"`
S
hexutil
.
Bytes
`json:"s" binding:"required"`
}
func
(
r
*
CancelOrderRequest
)
Recover
()
(
ok
bool
,
address
common
.
Address
)
{
data
:=
fmt
.
Sprintf
(
"baseToken=%s"eToken=%s&orderId=%s&nonce=%d"
,
r
.
BaseToken
,
r
.
QuoteToken
,
r
.
OrderId
,
r
.
Nonce
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
data
))
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
// combile sig
sig
:=
make
([]
byte
,
65
)
copy
(
sig
,
r
.
R
)
...
...
@@ -104,8 +110,9 @@ type SignProxyRequest struct {
}
func
(
r
*
SignProxyRequest
)
Recover
()
(
ok
bool
,
address
common
.
Address
)
{
data
:=
fmt
.
Sprintf
(
"s&agent=%s&nonce=%d"
,
r
.
Agent
,
r
.
Nonce
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
data
))
data
:=
fmt
.
Sprintf
(
"agent=%s&nonce=%d"
,
r
.
Agent
,
r
.
Nonce
)
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
// combile sig
sig
:=
make
([]
byte
,
65
)
copy
(
sig
,
r
.
R
)
...
...
cmd/
api
/main.go
→
cmd/
gateway
/main.go
View file @
eb086344
package
main
import
(
"log"
"github.com/exchain/process/api/handlers"
"github.com/exchain/process/api/router"
apigateway
"github.com/exchain/process/api/gateway"
"github.com/exchain/process/engine"
)
func
main
()
{
eg
:=
engine
.
GetEngine
()
// 创建订单处理器
orderHandler
:=
handlers
.
NewOrderHandler
(
eg
)
// 设置路由
r
:=
router
.
SetupRouter
(
orderHandler
)
// 启动服务器
if
err
:=
r
.
Run
(
":8080"
);
err
!=
nil
{
log
.
Fatalf
(
"Failed to start server: %v"
,
err
)
}
apigateway
.
StartServer
(
8111
,
8112
,
eg
)
}
engine/agent.go
View file @
eb086344
...
...
@@ -2,14 +2,29 @@ package engine
import
(
"errors"
"fmt"
"github.com/exchain/process/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
)
func
(
e
*
Engine
)
PorcessSignProxy
(
user
common
.
Address
,
proxy
common
.
Address
,
nonce
uint64
)
(
err
error
)
{
func
(
e
*
Engine
)
PorcessSignProxy
(
user
common
.
Address
,
proxy
common
.
Address
,
nonce
uint64
,
signature
[]
byte
)
(
err
error
)
{
data
:=
fmt
.
Sprintf
(
"agent=%s&nonce=%d"
,
proxy
.
Hex
(),
nonce
)
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
pubkey
,
err
:=
crypto
.
SigToPub
(
hashsum
.
Bytes
(),
signature
)
if
err
!=
nil
{
return
}
recovered
:=
crypto
.
PubkeyToAddress
(
*
pubkey
)
if
recovered
.
Hex
()
!=
user
.
Hex
()
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
userObject
,
err
:=
e
.
db
.
GetOrNewAccountObject
(
user
)
if
err
!=
nil
{
return
...
...
engine/engine.go
View file @
eb086344
...
...
@@ -125,11 +125,8 @@ func (e *Engine) NewPayload(params exchain.PayloadParams) (exchain.ExecutionResu
return
result
,
nil
}
func
(
e
*
Engine
)
ProcessPayload
(
block
*
nebulav1
.
Block
)
(
exchain
.
ExecutionResult
,
error
)
{
panic
(
"not implemented"
)
}
func
(
e
*
Engine
)
AddToQueue
(
tx
types
.
Transaction
)
{
r
,
s
,
v
:=
tx
.
GetRSV
()
switch
t
:=
tx
.
(
type
)
{
case
*
types
.
PlaceOrderTx
:
txType
:=
nebulav1
.
TxType_MarketTx
...
...
@@ -144,6 +141,12 @@ func (e *Engine) AddToQueue(tx types.Transaction) {
TxType
:
txType
,
User
:
t
.
User
.
Hex
(),
Nonce
:
t
.
GetNonce
(),
Proxy
:
t
.
Proxy
,
Signature
:
&
nebulav1
.
Signature
{
V
:
int32
(
v
),
R
:
r
,
S
:
s
,
},
Tx
:
&
nebulav1
.
Transaction_LimitTx
{
LimitTx
:
&
nebulav1
.
LimitOrderTransaction
{
Pair
:
t
.
GetPair
(),
...
...
@@ -159,6 +162,12 @@ func (e *Engine) AddToQueue(tx types.Transaction) {
TxType
:
nebulav1
.
TxType_CancelTx
,
User
:
t
.
User
.
Hex
(),
Nonce
:
t
.
GetNonce
(),
Proxy
:
t
.
Proxy
,
Signature
:
&
nebulav1
.
Signature
{
V
:
int32
(
v
),
R
:
r
,
S
:
s
,
},
Tx
:
&
nebulav1
.
Transaction_CancelTx
{
CancelTx
:
&
nebulav1
.
CancelOrderTransaction
{
OrderId
:
t
.
GetOrderID
(),
...
...
@@ -166,12 +175,17 @@ func (e *Engine) AddToQueue(tx types.Transaction) {
},
}
e
.
txQueue
<-
ptx
case
*
types
.
SignProxyTx
:
pTx
:=
&
nebulav1
.
Transaction
{
TxType
:
nebulav1
.
TxType_SignProxyTx
,
User
:
t
.
User
.
Hex
(),
Nonce
:
t
.
GetNonce
(),
Proxy
:
t
.
Proxy
,
Signature
:
&
nebulav1
.
Signature
{
V
:
int32
(
v
),
R
:
r
,
S
:
s
,
},
Tx
:
&
nebulav1
.
Transaction_SignProxyTx
{
SignProxyTx
:
&
nebulav1
.
SignProxyTransaction
{
SignerProxy
:
t
.
GetProxyAddress
()
.
Bytes
(),
...
...
engine/order.go
View file @
eb086344
...
...
@@ -2,17 +2,32 @@ package engine
import
(
"errors"
"fmt"
apiTypes
"github.com/exchain/process/api/types"
"github.com/exchain/process/orderbook"
"github.com/exchain/process/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
)
func
(
e
*
Engine
)
ProcessMarketOrder
(
orderId
string
,
baseToken
,
quoteToken
types
.
Coin
,
agent
common
.
Address
,
side
orderbook
.
Side
,
quantity
*
uint256
.
Int
,
nonce
uint64
)
(
tx
*
types
.
PlaceOrderTx
,
response
*
apiTypes
.
OrderResponse
,
err
error
)
{
func
(
e
*
Engine
)
ProcessMarketOrder
(
orderId
string
,
baseToken
,
quoteToken
types
.
Coin
,
agent
common
.
Address
,
side
orderbook
.
Side
,
quantity
*
uint256
.
Int
,
nonce
uint64
,
proxy
bool
,
signature
[]
byte
)
(
tx
*
types
.
PlaceOrderTx
,
response
*
apiTypes
.
OrderResponse
,
err
error
)
{
response
=
new
(
apiTypes
.
OrderResponse
)
data
:=
fmt
.
Sprintf
(
"baseToken=%s"eToken=%s&side=%s&quantity=%s&nonce=%d"
,
baseToken
,
quoteToken
,
side
,
quantity
.
String
(),
nonce
)
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
pubkey
,
err
:=
crypto
.
SigToPub
(
hashsum
.
Bytes
(),
signature
)
if
err
!=
nil
{
return
}
recovered
:=
crypto
.
PubkeyToAddress
(
*
pubkey
)
if
!
proxy
&&
(
recovered
.
Hex
()
!=
agent
.
Hex
())
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
e
.
Lock
()
ob
,
ok
:=
e
.
orderbooks
[
string
(
baseToken
+
quoteToken
)]
e
.
Unlock
()
...
...
@@ -21,7 +36,7 @@ func (e *Engine) ProcessMarketOrder(orderId string, baseToken, quoteToken types.
return
}
makerObj
,
err
:=
e
.
db
.
GetOrNewAc
ountObjectByAgen
t
(
agent
)
makerObj
,
err
:=
e
.
db
.
GetOrNewAc
countObjec
t
(
agent
)
if
err
!=
nil
{
return
}
...
...
@@ -31,6 +46,11 @@ func (e *Engine) ProcessMarketOrder(orderId string, baseToken, quoteToken types.
return
}
if
proxy
&&
(
recovered
.
Hex
()
!=
makerObj
.
Proxy
.
Hex
())
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
tx
=
new
(
types
.
PlaceOrderTx
)
tx
.
OrderID
=
orderId
tx
.
Nonce
=
nonce
...
...
@@ -39,6 +59,8 @@ func (e *Engine) ProcessMarketOrder(orderId string, baseToken, quoteToken types.
tx
.
BaseCoin
=
baseToken
tx
.
QuoteCoin
=
quoteToken
tx
.
Type
=
types
.
PlaceOrder
tx
.
Signature
=
signature
tx
.
Proxy
=
proxy
if
side
==
orderbook
.
Sell
{
tx
.
Action
=
types
.
OrderActionSell
}
else
{
...
...
@@ -147,8 +169,21 @@ func (e *Engine) ProcessMarketOrder(orderId string, baseToken, quoteToken types.
return
tx
,
response
,
nil
}
func
(
e
*
Engine
)
ProcessLimitOrder
(
orderId
string
,
baseToken
,
quoteToken
types
.
Coin
,
agent
common
.
Address
,
side
orderbook
.
Side
,
price
,
quantity
*
uint256
.
Int
,
nonce
uint64
)
(
tx
*
types
.
PlaceOrderTx
,
response
*
apiTypes
.
OrderResponse
,
err
error
)
{
func
(
e
*
Engine
)
ProcessLimitOrder
(
orderId
string
,
baseToken
,
quoteToken
types
.
Coin
,
agent
common
.
Address
,
side
orderbook
.
Side
,
price
,
quantity
*
uint256
.
Int
,
nonce
uint64
,
proxy
bool
,
signature
[]
byte
)
(
tx
*
types
.
PlaceOrderTx
,
response
*
apiTypes
.
OrderResponse
,
err
error
)
{
response
=
new
(
apiTypes
.
OrderResponse
)
data
:=
fmt
.
Sprintf
(
"baseToken=%s"eToken=%s&side=%s&quantity=%s&price=%s&nonce=%d"
,
baseToken
,
quoteToken
,
side
,
quantity
.
String
(),
price
.
String
(),
nonce
)
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
pubkey
,
err
:=
crypto
.
SigToPub
(
hashsum
.
Bytes
(),
signature
)
if
err
!=
nil
{
return
}
recovered
:=
crypto
.
PubkeyToAddress
(
*
pubkey
)
if
!
proxy
&&
(
recovered
.
Hex
()
!=
agent
.
Hex
())
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
e
.
Lock
()
ob
,
ok
:=
e
.
orderbooks
[
string
(
baseToken
+
quoteToken
)]
e
.
Unlock
()
...
...
@@ -157,15 +192,21 @@ func (e *Engine) ProcessLimitOrder(orderId string, baseToken, quoteToken types.C
return
}
makerObj
,
err
:=
e
.
db
.
GetOrNewAc
ountObjectByAgen
t
(
agent
)
makerObj
,
err
:=
e
.
db
.
GetOrNewAc
countObjec
t
(
agent
)
if
err
!=
nil
{
return
}
if
makerObj
==
nil
{
err
=
errors
.
New
(
"invalid agent"
)
return
}
if
proxy
&&
(
recovered
.
Hex
()
!=
makerObj
.
Proxy
.
Hex
())
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
tx
=
new
(
types
.
PlaceOrderTx
)
tx
.
OrderID
=
orderId
tx
.
Nonce
=
nonce
...
...
@@ -174,6 +215,8 @@ func (e *Engine) ProcessLimitOrder(orderId string, baseToken, quoteToken types.C
tx
.
BaseCoin
=
baseToken
tx
.
QuoteCoin
=
quoteToken
tx
.
Type
=
types
.
PlaceOrder
tx
.
Signature
=
signature
tx
.
Proxy
=
proxy
if
side
==
orderbook
.
Sell
{
tx
.
Action
=
types
.
OrderActionSell
}
else
{
...
...
@@ -285,7 +328,20 @@ func (e *Engine) ProcessLimitOrder(orderId string, baseToken, quoteToken types.C
return
tx
,
response
,
nil
}
func
(
e
*
Engine
)
ProcessCancelOrder
(
orderId
string
,
baseToken
,
quoteToken
types
.
Coin
,
agent
common
.
Address
,
nonce
uint64
)
(
err
error
)
{
func
(
e
*
Engine
)
ProcessCancelOrder
(
orderId
string
,
baseToken
,
quoteToken
types
.
Coin
,
agent
common
.
Address
,
nonce
uint64
,
proxy
bool
,
signature
[]
byte
)
(
err
error
)
{
data
:=
fmt
.
Sprintf
(
"baseToken=%s"eToken=%s&orderId=%s&nonce=%d"
,
baseToken
,
quoteToken
,
orderId
,
nonce
)
prefixedMessage
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
hashsum
:=
crypto
.
Keccak256Hash
([]
byte
(
prefixedMessage
))
pubkey
,
err
:=
crypto
.
SigToPub
(
hashsum
.
Bytes
(),
signature
)
if
err
!=
nil
{
return
}
recovered
:=
crypto
.
PubkeyToAddress
(
*
pubkey
)
if
!
proxy
&&
(
recovered
.
Hex
()
!=
agent
.
Hex
())
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
e
.
Lock
()
ob
,
ok
:=
e
.
orderbooks
[
string
(
baseToken
+
quoteToken
)]
e
.
Unlock
()
...
...
@@ -293,7 +349,7 @@ func (e *Engine) ProcessCancelOrder(orderId string, baseToken, quoteToken types.
return
}
makerObj
,
err
:=
e
.
db
.
GetOrNewAc
ountObjectByAgen
t
(
agent
)
makerObj
,
err
:=
e
.
db
.
GetOrNewAc
countObjec
t
(
agent
)
if
err
!=
nil
{
return
}
...
...
@@ -301,6 +357,11 @@ func (e *Engine) ProcessCancelOrder(orderId string, baseToken, quoteToken types.
return
errors
.
New
(
"invalid agent"
)
}
if
proxy
&&
(
recovered
.
Hex
()
!=
makerObj
.
Proxy
.
Hex
())
{
err
=
errors
.
New
(
"invalid signature"
)
return
}
order
:=
ob
.
Order
(
orderId
)
if
order
==
nil
{
return
errors
.
New
(
"invalid order id"
)
...
...
@@ -317,11 +378,16 @@ func (e *Engine) ProcessCancelOrder(orderId string, baseToken, quoteToken types.
tx
:=
&
types
.
CancelOrderTx
{
Tx
:
types
.
Tx
{
OrderID
:
orderId
,
Time
:
nonce
,
User
:
makerObj
.
Address
,
Action
:
types
.
OrderActionCancel
,
Nonce
:
nonce
,
OrderID
:
orderId
,
Time
:
nonce
,
User
:
makerObj
.
Address
,
BaseCoin
:
baseToken
,
QuoteCoin
:
quoteToken
,
Type
:
types
.
CancelOrder
,
Action
:
types
.
OrderActionCancel
,
Nonce
:
nonce
,
Proxy
:
proxy
,
Signature
:
signature
,
},
}
...
...
engine/process.go
View file @
eb086344
package
engine
import
(
"fmt"
"math/big"
"strings"
"github.com/exchain/process/orderbook"
"github.com/exchain/process/types"
"github.com/exchain/process/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/exchain/go-exchain/exchain"
"github.com/exchain/go-exchain/exchain/chaindb"
nebulav1
"github.com/exchain/go-exchain/exchain/protocol/gen/go/nebula/v1"
"github.com/exchain/go-exchain/exchain/wrapper"
"github.com/holiman/uint256"
)
func
(
e
*
Engine
)
ProcessPayload
(
block
*
nebulav1
.
Block
)
(
exchain
.
ExecutionResult
,
error
)
{
genesis
:=
block
.
Header
.
Height
==
0
if
!
genesis
{
parent
,
err
:=
e
.
chainDB
.
GetBlockByLabel
(
chaindb
.
ExChainBlockLatest
)
if
err
!=
nil
{
return
exchain
.
ExecutionResult
{},
err
}
if
parent
.
Header
.
Height
+
1
!=
block
.
Header
.
Height
{
return
exchain
.
ExecutionResult
{},
fmt
.
Errorf
(
"invalid block height"
)
}
}
receipts
,
err
:=
e
.
ProcessTx
(
block
.
Header
,
block
.
Transactions
)
if
err
!=
nil
{
return
exchain
.
ExecutionResult
{},
err
}
return
exchain
.
ExecutionResult
{
Payload
:
block
,
Receipts
:
receipts
,
},
nil
}
func
(
e
*
Engine
)
ProcessOrders
(
header
*
nebulav1
.
BlockHeader
)
(
txs
*
nebulav1
.
TransactionList
,
receipts
*
nebulav1
.
TransactionReceiptList
,
err
error
)
{
txs
=
&
nebulav1
.
TransactionList
{}
txs
.
Txs
=
make
([]
*
nebulav1
.
Transaction
,
0
)
...
...
@@ -131,6 +161,77 @@ func (e *Engine) ProcessTx(header *nebulav1.BlockHeader, txs *nebulav1.Transacti
receipt
.
Content
=
&
nebulav1
.
TransactionReceipt_DepositR
{
DepositR
:
&
nebulav1
.
DepositReceipt
{},
}
case
nebulav1
.
TxType_CreatePairTx
:
err
:=
e
.
ProcessCreatePair
(
tx
.
GetCreatePairTx
())
if
err
!=
nil
{
receipt
.
Success
=
false
}
receipt
.
Content
=
&
nebulav1
.
TransactionReceipt_CreatePairR
{
CreatePairR
:
&
nebulav1
.
CreatePairReceipt
{},
}
case
nebulav1
.
TxType_DisablePairTx
:
err
:=
e
.
ProcessDisablePair
(
tx
.
GetDisablePairTx
())
if
err
!=
nil
{
receipt
.
Success
=
false
}
receipt
.
Content
=
&
nebulav1
.
TransactionReceipt_DisablePairR
{
DisablePairR
:
&
nebulav1
.
DisablePairReceipt
{},
}
case
nebulav1
.
TxType_MarketTx
:
coins
:=
strings
.
Split
(
tx
.
GetMarketTx
()
.
Pair
,
"-"
)
baseCoin
:=
types
.
Coin
(
coins
[
0
])
quoteCoin
:=
types
.
Coin
(
coins
[
1
])
user
:=
common
.
HexToAddress
(
tx
.
User
)
side
:=
orderbook
.
Buy
if
tx
.
GetMarketTx
()
.
Side
==
nebulav1
.
OrderSide_SELL
{
side
=
orderbook
.
Sell
}
quantity
:=
new
(
uint256
.
Int
)
.
SetBytes
(
tx
.
GetMarketTx
()
.
Quantity
)
nonce
:=
new
(
big
.
Int
)
.
SetBytes
(
tx
.
Nonce
)
_
,
_
,
err
:=
e
.
ProcessMarketOrder
(
tx
.
GetMarketTx
()
.
OrderId
,
baseCoin
,
quoteCoin
,
user
,
side
,
quantity
,
nonce
.
Uint64
(),
tx
.
Proxy
,
utils
.
CombineRSV
(
tx
.
Signature
.
R
,
tx
.
Signature
.
S
,
uint8
(
tx
.
Signature
.
V
)))
if
err
!=
nil
{
receipt
.
Success
=
false
}
receipt
.
Content
=
&
nebulav1
.
TransactionReceipt_MarketR
{
MarketR
:
&
nebulav1
.
MarketOrderReceipt
{},
}
case
nebulav1
.
TxType_LimitTx
:
coins
:=
strings
.
Split
(
tx
.
GetLimitTx
()
.
Pair
,
"-"
)
baseCoin
:=
types
.
Coin
(
coins
[
0
])
quoteCoin
:=
types
.
Coin
(
coins
[
1
])
user
:=
common
.
HexToAddress
(
tx
.
User
)
side
:=
orderbook
.
Buy
if
tx
.
GetLimitTx
()
.
Side
==
nebulav1
.
OrderSide_SELL
{
side
=
orderbook
.
Sell
}
quantity
:=
new
(
uint256
.
Int
)
.
SetBytes
(
tx
.
GetLimitTx
()
.
Quantity
)
price
:=
new
(
uint256
.
Int
)
.
SetBytes
(
tx
.
GetLimitTx
()
.
Price
)
nonce
:=
new
(
big
.
Int
)
.
SetBytes
(
tx
.
Nonce
)
_
,
_
,
err
:=
e
.
ProcessLimitOrder
(
tx
.
GetLimitTx
()
.
OrderId
,
baseCoin
,
quoteCoin
,
user
,
side
,
quantity
,
price
,
nonce
.
Uint64
(),
tx
.
Proxy
,
utils
.
CombineRSV
(
tx
.
Signature
.
R
,
tx
.
Signature
.
S
,
uint8
(
tx
.
Signature
.
V
)))
if
err
!=
nil
{
receipt
.
Success
=
false
}
receipt
.
Content
=
&
nebulav1
.
TransactionReceipt_LimitR
{
LimitR
:
&
nebulav1
.
LimitOrderReceipt
{},
}
case
nebulav1
.
TxType_CancelTx
:
coins
:=
strings
.
Split
(
tx
.
GetCancelTx
()
.
Pair
,
"-"
)
baseCoin
:=
types
.
Coin
(
coins
[
0
])
quoteCoin
:=
types
.
Coin
(
coins
[
1
])
user
:=
common
.
HexToAddress
(
tx
.
User
)
err
:=
e
.
ProcessCancelOrder
(
tx
.
GetCancelTx
()
.
OrderId
,
baseCoin
,
quoteCoin
,
user
,
new
(
big
.
Int
)
.
SetBytes
(
tx
.
Nonce
)
.
Uint64
(),
tx
.
Proxy
,
utils
.
CombineRSV
(
tx
.
Signature
.
R
,
tx
.
Signature
.
S
,
uint8
(
tx
.
Signature
.
V
)))
if
err
!=
nil
{
receipt
.
Success
=
false
}
receipt
.
Content
=
&
nebulav1
.
TransactionReceipt_CancelR
{
CancelR
:
&
nebulav1
.
CancelOrderReceipt
{},
}
default
:
}
receipts
.
Receipts
=
append
(
receipts
.
Receipts
,
receipt
)
...
...
go.mod
View file @
eb086344
...
...
@@ -5,55 +5,59 @@ go 1.23.3
require (
github.com/bwmarrin/snowflake v0.3.0
github.com/emirpasic/gods v1.18.1
github.com/ethereum/go-ethereum v1.15.
0
github.com/ethereum/go-ethereum v1.15.
7
github.com/exchain/go-exchain v0.0.1
github.com/gin-gonic/gin v1.10.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/holiman/uint256 v1.3.2
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a
google.golang.org/grpc v1.57.1
)
require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.
3
.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.
4
.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/golang-lru v
0.5.0
// indirect
github.com/hashicorp/golang-lru v
1.0.2
// indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
)
require (
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/bytedance/sonic v1.13.2 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gin-contrib/sse v1.0.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.2
0
.0 // indirect
github.com/goccy/go-json v0.10.
3
// indirect
github.com/golang/snappy v
0.0.5-0.20220116011046-fa5810519dcb
// indirect
github.com/go-playground/validator/v10 v10.2
6
.0 // indirect
github.com/goccy/go-json v0.10.
5
// indirect
github.com/golang/snappy v
1.0.0
// indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.
8
// indirect
github.com/klauspost/cpuid/v2 v2.2.
10
// indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.
2
// indirect
github.com/pelletier/go-toml/v2 v2.2.
3
// indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.1
2
// indirect
github.com/tklauser/numcpus v0.
6.1
// indirect
github.com/tklauser/go-sysconf v0.3.1
5
// indirect
github.com/tklauser/numcpus v0.
10.0
// indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/arch v0.16.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
google.golang.org/genproto v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
...
...
go.sum
View file @
eb086344
This diff is collapsed.
Click to expand it.
types/transaction.go
View file @
eb086344
...
...
@@ -5,6 +5,7 @@ import (
"encoding/gob"
"github.com/ethereum/go-ethereum/common"
"github.com/exchain/process/utils"
"github.com/holiman/uint256"
)
...
...
@@ -35,6 +36,7 @@ type Transaction interface {
GetOrderID
()
string
GetNonce
()
[]
byte
GetProxyAddress
()
common
.
Address
GetRSV
()
(
r
,
s
[]
byte
,
v
uint8
)
}
type
Tx
struct
{
...
...
@@ -46,6 +48,8 @@ type Tx struct {
Type
OrderType
Action
OrderAction
Nonce
uint64
Proxy
bool
Signature
[]
byte
}
type
CancelOrderTx
struct
{
...
...
@@ -71,6 +75,11 @@ func (tx *CancelOrderTx) GetUser() common.Address {
return
tx
.
User
}
func
(
tx
*
CancelOrderTx
)
GetRSV
()
(
r
,
s
[]
byte
,
v
uint8
)
{
r
,
s
,
v
=
utils
.
SplitRSV
(
tx
.
Signature
)
return
}
func
(
tx
*
CancelOrderTx
)
GetLimitPrice
()
*
uint256
.
Int
{
return
nil
}
...
...
@@ -152,6 +161,11 @@ func (tx *PlaceOrderTx) GetProxyAddress() common.Address {
return
common
.
Address
{}
}
func
(
tx
*
PlaceOrderTx
)
GetRSV
()
(
r
,
s
[]
byte
,
v
uint8
)
{
r
,
s
,
v
=
utils
.
SplitRSV
(
tx
.
Signature
)
return
}
type
SignProxyTx
struct
{
Tx
ProxyAddress
common
.
Address
...
...
@@ -203,3 +217,8 @@ func (tx *SignProxyTx) GetNonce() []byte {
func
(
tx
*
SignProxyTx
)
GetProxyAddress
()
common
.
Address
{
return
tx
.
ProxyAddress
}
func
(
tx
*
SignProxyTx
)
GetRSV
()
(
r
,
s
[]
byte
,
v
uint8
)
{
r
,
s
,
v
=
utils
.
SplitRSV
(
tx
.
Signature
)
return
}
utils/signature.go
0 → 100644
View file @
eb086344
package
utils
func
SplitRSV
(
signature
[]
byte
)
(
r
,
s
[]
byte
,
v
uint8
)
{
r
=
signature
[
:
32
]
s
=
signature
[
32
:
64
]
v
=
signature
[
64
]
return
}
func
CombineRSV
(
r
,
s
[]
byte
,
v
uint8
)
[]
byte
{
return
append
(
append
(
r
,
s
...
),
v
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment