all: remove XDCx and XDCxlending public API, close XFN-74 XFN-134 (#1675)

* internal: remove XDCx public API

* XDCx, XDCxlending: remove api

* ethclient: remove SendOrderTransaction and SendLendingTransaction

* XDCx, XDCxlending: remove unused variables and function

* eth, internal/ethapi: remove function `OrderStats()`
This commit is contained in:
Daniel Liu 2025-11-04 13:49:16 +08:00 committed by GitHub
parent 8ca35720cd
commit 13ed19bcf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 14 additions and 1810 deletions

View file

@ -17,16 +17,9 @@ import (
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/node"
"github.com/XinFinOrg/XDPoSChain/p2p"
"github.com/XinFinOrg/XDPoSChain/rpc"
"golang.org/x/sync/syncmap"
)
const (
ProtocolName = "XDCx"
ProtocolVersion = uint64(1)
ProtocolVersionStr = "1.0"
overflowIdx // Indicator of message queue overflow
defaultCacheLimit = 1024
MaximumTxMatchSize = 1000
)
@ -56,26 +49,11 @@ type XDCX struct {
Triegc *prque.Prque[int64, common.Hash] // Priority queue mapping block numbers to tries to gc
StateCache tradingstate.Database // State database to reuse between imports (contains state cache) *XDCx_state.TradingStateDB
orderNonce map[common.Address]*big.Int
sdkNode bool
settings syncmap.Map // holds configuration settings that can be dynamically changed
tokenDecimalCache *lru.Cache[common.Address, *big.Int]
orderCache *lru.Cache[common.Hash, map[common.Hash]tradingstate.OrderHistoryItem]
}
func (XDCx *XDCX) Protocols() []p2p.Protocol {
return []p2p.Protocol{}
}
func (XDCx *XDCX) Start() error {
return nil
}
func (XDCx *XDCX) Stop() error {
return nil
}
func NewLDBEngine(cfg *Config) *XDCxDAO.BatchDatabase {
datadir := cfg.DataDir
batchDB := XDCxDAO.NewBatchDatabaseWithEncode(datadir, 0)
@ -94,7 +72,6 @@ func NewMongoDBEngine(cfg *Config) *XDCxDAO.MongoDatabase {
func New(stack *node.Node, cfg *Config) *XDCX {
XDCX := &XDCX{
orderNonce: make(map[common.Address]*big.Int),
Triegc: prque.New[int64, common.Hash](nil),
tokenDecimalCache: lru.NewCache[common.Address, *big.Int](defaultCacheLimit),
orderCache: lru.NewCache[common.Hash, map[common.Hash]tradingstate.OrderHistoryItem](tradingstate.OrderCacheLimit),
@ -110,23 +87,10 @@ func New(stack *node.Node, cfg *Config) *XDCX {
}
XDCX.StateCache = tradingstate.NewDatabase(XDCX.db)
XDCX.settings.Store(overflowIdx, false)
stack.RegisterAPIs(XDCX.APIs())
stack.RegisterProtocols(XDCX.Protocols())
stack.RegisterLifecycle(XDCX)
return XDCX
}
// Overflow returns an indication if the message queue is full.
func (XDCx *XDCX) Overflow() bool {
val, ok := XDCx.settings.Load(overflowIdx)
if !ok {
log.Warn("[XDCx-Overflow] fail to load overflow index")
}
return val.(bool)
}
func (XDCx *XDCX) IsSDKNode() bool {
return XDCx.sdkNode
}
@ -139,21 +103,6 @@ func (XDCx *XDCX) GetMongoDB() XDCxDAO.XDCXDAO {
return XDCx.mongodb
}
// APIs returns the RPC descriptors the XDCX implementation offers
func (XDCx *XDCX) APIs() []rpc.API {
return []rpc.API{
{
Namespace: ProtocolName,
Service: NewPublicXDCXAPI(XDCx),
},
}
}
// Version returns the XDCX sub-protocols version number.
func (XDCx *XDCX) Version() uint64 {
return ProtocolVersion
}
func (XDCx *XDCX) ProcessOrderPending(header *types.Header, coinbase common.Address, chain consensus.ChainContext, pending map[common.Address]types.OrderTransactions, statedb *state.StateDB, XDCXstatedb *tradingstate.TradingStateDB) ([]tradingstate.TxDataMatch, map[common.Hash]tradingstate.MatchingResult) {
txMatches := []tradingstate.TxDataMatch{}
matchingResults := map[common.Hash]tradingstate.MatchingResult{}

View file

@ -1,42 +0,0 @@
package XDCx
import (
"context"
"errors"
"sync"
"time"
)
const (
LimitThresholdOrderNonceInQueue = 100
)
// List of errors
var (
ErrNoTopics = errors.New("missing topic(s)")
ErrOrderNonceTooLow = errors.New("OrderNonce too low")
ErrOrderNonceTooHigh = errors.New("OrderNonce too high")
)
// PublicXDCXAPI provides the XDCX RPC service that can be
// use publicly without security implications.
type PublicXDCXAPI struct {
t *XDCX
mu sync.Mutex
lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
}
// NewPublicXDCXAPI create a new RPC XDCX service.
func NewPublicXDCXAPI(t *XDCX) *PublicXDCXAPI {
api := &PublicXDCXAPI{
t: t,
lastUsed: make(map[string]time.Time),
}
return api
}
// Version returns the XDCX sub-protocol version.
func (api *PublicXDCXAPI) Version(ctx context.Context) string {
return ProtocolVersionStr
}

View file

@ -20,15 +20,10 @@ import (
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/node"
"github.com/XinFinOrg/XDPoSChain/p2p"
"github.com/XinFinOrg/XDPoSChain/rpc"
)
const (
ProtocolName = "XDCxlending"
ProtocolVersion = uint64(1)
ProtocolVersionStr = "1.0"
defaultCacheLimit = 1024
defaultCacheLimit = 1024
)
var (
@ -40,28 +35,13 @@ type Lending struct {
Triegc *prque.Prque[int64, common.Hash] // Priority queue mapping block numbers to tries to gc
StateCache lendingstate.Database // State database to reuse between imports (contains state cache) *lendingstate.TradingStateDB
orderNonce map[common.Address]*big.Int
XDCx *XDCx.XDCX
lendingItemHistory *lru.Cache[common.Hash, map[common.Hash]lendingstate.LendingItemHistoryItem]
lendingTradeHistory *lru.Cache[common.Hash, map[common.Hash]lendingstate.LendingTradeHistoryItem]
}
func (l *Lending) Protocols() []p2p.Protocol {
return []p2p.Protocol{}
}
func (l *Lending) Start() error {
return nil
}
func (l *Lending) Stop() error {
return nil
}
func New(stack *node.Node, XDCx *XDCx.XDCX) *Lending {
lending := &Lending{
orderNonce: make(map[common.Address]*big.Int),
Triegc: prque.New[int64, common.Hash](nil),
lendingItemHistory: lru.NewCache[common.Hash, map[common.Hash]lendingstate.LendingItemHistoryItem](defaultCacheLimit),
lendingTradeHistory: lru.NewCache[common.Hash, map[common.Hash]lendingstate.LendingTradeHistoryItem](defaultCacheLimit),
@ -69,11 +49,6 @@ func New(stack *node.Node, XDCx *XDCx.XDCX) *Lending {
lending.StateCache = lendingstate.NewDatabase(XDCx.GetLevelDB())
lending.XDCx = XDCx
// Register the backend on the node
stack.RegisterAPIs(lending.APIs())
stack.RegisterProtocols(lending.Protocols())
stack.RegisterLifecycle(lending)
return lending
}
@ -85,21 +60,6 @@ func (l *Lending) GetMongoDB() XDCxDAO.XDCXDAO {
return l.XDCx.GetMongoDB()
}
// APIs returns the RPC descriptors the Lending implementation offers
func (l *Lending) APIs() []rpc.API {
return []rpc.API{
{
Namespace: ProtocolName,
Service: NewPublicXDCXLendingAPI(l),
},
}
}
// Version returns the Lending sub-protocols version number.
func (l *Lending) Version() uint64 {
return ProtocolVersion
}
func (l *Lending) ProcessOrderPending(header *types.Header, coinbase common.Address, chain consensus.ChainContext, pending map[common.Address]types.LendingTransactions, statedb *state.StateDB, lendingStatedb *lendingstate.LendingStateDB, tradingStateDb *tradingstate.TradingStateDB) ([]*lendingstate.LendingItem, map[common.Hash]lendingstate.MatchingResult) {
lendingItems := []*lendingstate.LendingItem{}
matchingResults := map[common.Hash]lendingstate.MatchingResult{}

View file

@ -1,37 +0,0 @@
package XDCxlending
import (
"context"
"errors"
"sync"
"time"
)
// List of errors
var (
ErrOrderNonceTooLow = errors.New("OrderNonce too low")
ErrOrderNonceTooHigh = errors.New("OrderNonce too high")
)
// PublicXDCXLendingAPI provides the XDCX RPC service that can be
// use publicly without security implications.
type PublicXDCXLendingAPI struct {
t *Lending
mu sync.Mutex
lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
}
// NewPublicXDCXLendingAPI create a new RPC XDCX service.
func NewPublicXDCXLendingAPI(t *Lending) *PublicXDCXLendingAPI {
api := &PublicXDCXLendingAPI{
t: t,
lastUsed: make(map[string]time.Time),
}
return api
}
// Version returns the Lending sub-protocol version.
func (api *PublicXDCXLendingAPI) Version(ctx context.Context) string {
return ProtocolVersionStr
}

View file

@ -30,7 +30,7 @@ import (
)
const (
ipcAPIs = "XDCx:1.0 XDCxlending:1.0 XDPoS:1.0 admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 txpool:1.0 web3:1.0"
ipcAPIs = "XDPoS:1.0 admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 txpool:1.0 web3:1.0"
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0"
)

View file

@ -1,20 +1,12 @@
package txpool
import (
"context"
"fmt"
"log"
"math/big"
"strconv"
"strings"
"testing"
"time"
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/ethclient"
"github.com/XinFinOrg/XDPoSChain/rpc"
"golang.org/x/crypto/sha3"
)
@ -120,165 +112,3 @@ func (l *LendingMsg) computeHash() common.Hash {
return common.BytesToHash(sha.Sum(nil))
}
func testSendLending(key string, nonce uint64, lendToken, collateralToken common.Address, amount *big.Int, interest uint64, side string, status string, autoTopUp bool, lendingId, tradeId uint64, cancelledHash common.Hash, extraData string) {
client, err := ethclient.Dial("http://127.0.0.1:8501")
if err != nil {
log.Print(err)
}
privateKey, err := crypto.HexToECDSA(key)
if err != nil {
log.Print(err)
}
msg := &LendingMsg{
AccountNonce: nonce,
Quantity: amount,
RelayerAddress: common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"),
UserAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
LendingToken: lendToken,
Status: status,
Side: side,
Type: "LO",
Term: 86400,
AutoTopUp: autoTopUp,
Interest: interest,
LendingId: lendingId,
LendingTradeId: tradeId,
ExtraData: extraData,
}
if msg.Side == lendingstate.Borrowing {
msg.CollateralToken = collateralToken
}
if cancelledHash != (common.Hash{}) {
msg.Hash = cancelledHash
} else {
msg.Hash = msg.computeHash()
}
tx := types.NewLendingTransaction(msg.AccountNonce, msg.Quantity, msg.Interest, msg.Term, msg.RelayerAddress, msg.UserAddress, msg.LendingToken, msg.CollateralToken, msg.AutoTopUp, msg.Status, msg.Side, msg.Type, msg.Hash, lendingId, tradeId, msg.ExtraData)
signedTx, err := types.LendingSignTx(tx, types.LendingTxSigner{}, privateKey)
if err != nil {
log.Print(err)
}
fmt.Println("nonce", nonce, "side", msg.Side, "quantity", new(big.Int).Div(msg.Quantity, _1E8), "Interest", new(big.Int).Div(new(big.Int).SetUint64(msg.Interest), _1E8), "%")
err = client.SendLendingTransaction(context.Background(), signedTx)
if err != nil {
log.Print(err)
}
}
func TestSendLending(t *testing.T) {
t.SkipNow() //TODO: remove it to run this test
key := ""
privateKey, err := crypto.HexToECDSA(key)
if err != nil {
log.Print(err)
}
nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
if err != nil {
t.Fatal("fail to get nonce")
}
for {
// 10%
interestRate := 10 * common.BaseLendingInterest.Uint64()
// lendToken: USD, collateral: BTC
// amount 1000 USD
testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
testSendLending(key, nonce, USDAddress, BTCAddress, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
// lendToken: USD, collateral: XDC
// amount 1000 USD
testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
testSendLending(key, nonce, USDAddress, common.XDCNativeAddressBinary, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
// lendToken: BTC, collateral: XDC
// amount 1 BTC
testSendLending(key, nonce, BTCAddress, common.Address{}, new(big.Int).Mul(_1E18, big.NewInt(1)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
testSendLending(key, nonce, BTCAddress, common.XDCNativeAddressBinary, new(big.Int).Mul(_1E18, big.NewInt(1)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
// lendToken: BTC, collateral: ETH
// amount 1 BTC
testSendLending(key, nonce, BTCAddress, common.Address{}, new(big.Int).Mul(_1E18, big.NewInt(1)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
testSendLending(key, nonce, BTCAddress, ETHAddress, new(big.Int).Mul(_1E18, big.NewInt(1)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
// lendToken: XDC, collateral: BTC
// amount 1000 XDC
testSendLending(key, nonce, common.XDCNativeAddressBinary, common.Address{}, new(big.Int).Mul(_1E18, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
testSendLending(key, nonce, common.XDCNativeAddressBinary, BTCAddress, new(big.Int).Mul(_1E18, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
// lendToken: XDC, collateral: ETH
// amount 1000 XDC
testSendLending(key, nonce, common.XDCNativeAddressBinary, common.Address{}, new(big.Int).Mul(_1E18, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
testSendLending(key, nonce, common.XDCNativeAddressBinary, ETHAddress, new(big.Int).Mul(_1E18, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(time.Second)
}
}
func TestCancelLending(t *testing.T) {
t.SkipNow() //TODO: remove it to run this test
key := ""
privateKey, err := crypto.HexToECDSA(key)
if err != nil {
log.Print(err)
}
nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
if err != nil {
t.Fatal("fail to get nonce")
}
// 10%
interestRate := 10 * common.BaseLendingInterest.Uint64()
testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
nonce++
time.Sleep(2 * time.Second)
//TODO: run the above testcase first, then updating lendingId, Hash
testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusCancelled, true, 1, 0, common.HexToHash("0x3da4e24b9c0f60e04cdb4c4494de37203c6e1a354907cbd6d9bbbe2e52aecaab"), "")
}
func TestRecallLending(t *testing.T) {
t.SkipNow() //TODO: remove it to run this test
key := ""
privateKey, err := crypto.HexToECDSA(key)
if err != nil {
log.Print(err)
}
nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
if err != nil {
t.Fatal("fail to get nonce")
}
interestRate := 10 * common.BaseLendingInterest.Uint64()
testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
time.Sleep(2 * time.Second)
nonce, err = getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
if err != nil {
t.Fatal("fail to get nonce")
}
testSendLending(key, nonce, USDAddress, common.XDCNativeAddressBinary, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
time.Sleep(2 * time.Second)
}

View file

@ -1,310 +0,0 @@
package txpool
import (
"context"
"log"
"math/big"
"strconv"
"strings"
"testing"
"time"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/ethclient"
"github.com/XinFinOrg/XDPoSChain/rpc"
)
type OrderMsg struct {
AccountNonce uint64 `json:"nonce" gencodec:"required"`
Quantity *big.Int `json:"quantity,omitempty"`
Price *big.Int `json:"price,omitempty"`
ExchangeAddress common.Address `json:"exchangeAddress,omitempty"`
UserAddress common.Address `json:"userAddress,omitempty"`
BaseToken common.Address `json:"baseToken,omitempty"`
QuoteToken common.Address `json:"quoteToken,omitempty"`
Status string `json:"status,omitempty"`
Side string `json:"side,omitempty"`
Type string `json:"type,omitempty"`
OrderID uint64 `json:"orderid,omitempty"`
// Signature values
V *big.Int `json:"v" gencodec:"required"`
R *big.Int `json:"r" gencodec:"required"`
S *big.Int `json:"s" gencodec:"required"`
// This is only used when marshaling to JSON.
Hash common.Hash `json:"hash" rlp:"-"`
}
var (
BTCAddress = common.HexToAddress("0xC2fa1BA90b15E3612E0067A0020192938784D9C5")
ETHAddress = common.HexToAddress("0xAad540ac542C3688652a3fc7b8e21B3fC1D097e9")
XRPAddress = common.HexToAddress("0x5dc27D59bB80E0EF853Bb2e27B94113DF08F547F")
LTCAddress = common.HexToAddress("0x6F98655A8fa7AEEF3147ee002c666d09c7AA4F5c")
BNBAddress = common.HexToAddress("0xaC389aCA56394a5B14918cF6437600760B6c650C")
ADAAddress = common.HexToAddress("0x576201Ac3f1E0fe483a9320DaCc4B08EB3E58306")
ETCAddress = common.HexToAddress("0xf992cf45394dAc5f50A26446de17803a79B940da")
BCHAddress = common.HexToAddress("0xFDF68dE6dFFd893221fc9f7985FeBC2AB20761A6")
EOSAddress = common.HexToAddress("0xd9bb01454c85247B2ef35BB5BE57384cC275a8cf")
USDAddress = common.HexToAddress("0x45c25041b8e6CBD5c963E7943007187C3673C7c9")
_1E18 = new(big.Int).Mul(big.NewInt(10000000000000000), big.NewInt(100))
_1E8 = big.NewInt(100000000)
_1E7 = big.NewInt(10000000)
)
func getNonce(t *testing.T, userAddress common.Address) (uint64, error) {
rpcClient, err := rpc.DialHTTP("http://127.0.0.1:8501")
if err != nil {
return 0, err
}
defer rpcClient.Close()
var result interface{}
err = rpcClient.Call(&result, "XDCx_getOrderCount", userAddress)
if err != nil {
return 0, err
}
s := result.(string)
s = strings.TrimPrefix(s, "0x")
n, err := strconv.ParseUint(s, 16, 32)
return n, err
}
func testSendOrder(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {
client, err := ethclient.Dial("http://127.0.0.1:8501")
if err != nil {
log.Print(err)
}
privateKey, err := crypto.HexToECDSA("65ec4d4dfbcac594a14c36baa462d6f73cd86134840f6cf7b80a1e1cd33473e2")
if err != nil {
log.Print(err)
}
msg := &OrderMsg{
Quantity: amount,
Price: price,
ExchangeAddress: common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"),
UserAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
BaseToken: common.XDCNativeAddressBinary,
QuoteToken: BTCAddress,
Status: status,
Side: side,
Type: "LO",
}
nonce, _ := getNonce(t, msg.UserAddress)
tx := types.NewOrderTransaction(nonce, msg.Quantity, msg.Price, msg.ExchangeAddress, msg.UserAddress, msg.BaseToken, msg.QuoteToken, msg.Status, msg.Side, msg.Type, common.Hash{}, orderID)
signedTx, err := types.OrderSignTx(tx, types.OrderTxSigner{}, privateKey)
if err != nil {
log.Print(err)
}
err = client.SendOrderTransaction(context.Background(), signedTx)
if err != nil {
log.Print(err)
}
}
func testSendOrderXDCUSD(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {
client, err := ethclient.Dial("http://127.0.0.1:8501")
if err != nil {
log.Print(err)
}
privateKey, err := crypto.HexToECDSA("65ec4d4dfbcac594a14c36baa462d6f73cd86134840f6cf7b80a1e1cd33473e2")
if err != nil {
log.Print(err)
}
msg := &OrderMsg{
Quantity: amount,
Price: price,
ExchangeAddress: common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"),
UserAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
BaseToken: common.XDCNativeAddressBinary,
QuoteToken: USDAddress,
Status: status,
Side: side,
Type: "LO",
}
nonce, _ := getNonce(t, msg.UserAddress)
tx := types.NewOrderTransaction(nonce, msg.Quantity, msg.Price, msg.ExchangeAddress, msg.UserAddress, msg.BaseToken, msg.QuoteToken, msg.Status, msg.Side, msg.Type, common.Hash{}, orderID)
signedTx, err := types.OrderSignTx(tx, types.OrderTxSigner{}, privateKey)
if err != nil {
log.Print(err)
}
err = client.SendOrderTransaction(context.Background(), signedTx)
if err != nil {
log.Print(err)
}
}
func testSendOrderBTCUSD(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {
client, err := ethclient.Dial("http://127.0.0.1:8501")
if err != nil {
log.Print(err)
}
privateKey, err := crypto.HexToECDSA("65ec4d4dfbcac594a14c36baa462d6f73cd86134840f6cf7b80a1e1cd33473e2")
if err != nil {
log.Print(err)
}
msg := &OrderMsg{
Quantity: amount,
Price: price,
ExchangeAddress: common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"),
UserAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
BaseToken: BTCAddress,
QuoteToken: USDAddress,
Status: status,
Side: side,
Type: "LO",
}
nonce, _ := getNonce(t, msg.UserAddress)
tx := types.NewOrderTransaction(nonce, msg.Quantity, msg.Price, msg.ExchangeAddress, msg.UserAddress, msg.BaseToken, msg.QuoteToken, msg.Status, msg.Side, msg.Type, common.Hash{}, orderID)
signedTx, err := types.OrderSignTx(tx, types.OrderTxSigner{}, privateKey)
if err != nil {
log.Print(err)
}
err = client.SendOrderTransaction(context.Background(), signedTx)
if err != nil {
log.Print(err)
}
}
func testSendOrderXDCBTC(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {
client, err := ethclient.Dial("http://127.0.0.1:8501")
if err != nil {
log.Print(err)
}
privateKey, err := crypto.HexToECDSA("65ec4d4dfbcac594a14c36baa462d6f73cd86134840f6cf7b80a1e1cd33473e2")
if err != nil {
log.Print(err)
}
msg := &OrderMsg{
Quantity: amount,
Price: price,
ExchangeAddress: common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"),
UserAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
BaseToken: common.XDCNativeAddressBinary,
QuoteToken: BTCAddress,
Status: status,
Side: side,
Type: "LO",
}
nonce, _ := getNonce(t, msg.UserAddress)
tx := types.NewOrderTransaction(nonce, msg.Quantity, msg.Price, msg.ExchangeAddress, msg.UserAddress, msg.BaseToken, msg.QuoteToken, msg.Status, msg.Side, msg.Type, common.Hash{}, orderID)
signedTx, err := types.OrderSignTx(tx, types.OrderTxSigner{}, privateKey)
if err != nil {
log.Print(err)
}
err = client.SendOrderTransaction(context.Background(), signedTx)
if err != nil {
log.Print(err)
}
}
func testSendOrderETHBTC(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {
client, err := ethclient.Dial("http://127.0.0.1:8501")
if err != nil {
log.Print(err)
}
privateKey, err := crypto.HexToECDSA("65ec4d4dfbcac594a14c36baa462d6f73cd86134840f6cf7b80a1e1cd33473e2")
if err != nil {
log.Print(err)
}
msg := &OrderMsg{
Quantity: amount,
Price: price,
ExchangeAddress: common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e"),
UserAddress: crypto.PubkeyToAddress(privateKey.PublicKey),
BaseToken: ETHAddress,
QuoteToken: BTCAddress,
Status: status,
Side: side,
Type: "LO",
}
nonce, _ := getNonce(t, msg.UserAddress)
tx := types.NewOrderTransaction(nonce, msg.Quantity, msg.Price, msg.ExchangeAddress, msg.UserAddress, msg.BaseToken, msg.QuoteToken, msg.Status, msg.Side, msg.Type, common.Hash{}, orderID)
signedTx, err := types.OrderSignTx(tx, types.OrderTxSigner{}, privateKey)
if err != nil {
log.Print(err)
}
err = client.SendOrderTransaction(context.Background(), signedTx)
if err != nil {
log.Print(err)
}
}
func TestSendBuyOrder(t *testing.T) {
testSendOrder(t, new(big.Int).SetUint64(1000000000000000000), new(big.Int).SetUint64(100000000000000000), "BUY", "NEW", 0)
}
func TestSendSellOrder(t *testing.T) {
testSendOrder(t, new(big.Int).SetUint64(1000000000000000000), new(big.Int).SetUint64(100000000000000000), "SELL", "NEW", 0)
}
func TestFilled(t *testing.T) {
////BTC/XDC
//BTCUSDPrice := new(big.Int).Mul(big.NewInt(1000000000000000000), big.NewInt(5000))
//testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(1000000000000000000), big.NewInt(5000)), BTCUSDPrice, "BUY", "NEW", 0)
//ETH/BTC
BTCUSDPrice := new(big.Int).Mul(_1E8, big.NewInt(10000)) // 10000
time.Sleep(2 * time.Second)
testSendOrderBTCUSD(t, _1E18, BTCUSDPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderBTCUSD(t, _1E18, BTCUSDPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderBTCUSD(t, new(big.Int).Mul(big.NewInt(2), _1E18), BTCUSDPrice, "SELL", "NEW", 0)
XDCBTCPrice := new(big.Int).Mul(big.NewInt(10000000000000), big.NewInt(6)) // 0.00006
time.Sleep(2 * time.Second)
testSendOrderXDCBTC(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCBTCPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderXDCBTC(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCBTCPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderXDCBTC(t, new(big.Int).Mul(big.NewInt(1200000), _1E18), XDCBTCPrice, "SELL", "NEW", 0)
XDCUSDPrice := new(big.Int).Mul(_1E7, big.NewInt(6)) // 0.6
time.Sleep(2 * time.Second)
testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCUSDPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCUSDPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(1200000), _1E18), XDCUSDPrice, "SELL", "NEW", 0)
}
func TestX10Filled(t *testing.T) {
XDCUSDPrice := new(big.Int).Mul(_1E7, big.NewInt(60)) // 6
time.Sleep(2 * time.Second)
testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCUSDPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCUSDPrice, "BUY", "NEW", 0)
time.Sleep(2 * time.Second)
testSendOrderXDCUSD(t, new(big.Int).Mul(big.NewInt(1200000), _1E18), XDCUSDPrice, "SELL", "NEW", 0)
}
func TestPartialFilled(t *testing.T) {
}
func TestNoMatch(t *testing.T) {
}
func TestCancelOrder(t *testing.T) {
XDCBTCPrice := new(big.Int).Mul(big.NewInt(10000000000000), big.NewInt(6)) // 0.00006
testSendOrder(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCBTCPrice, "BUY", "NEW", 0)
time.Sleep(5 * time.Second)
testSendOrder(t, new(big.Int).Mul(big.NewInt(600000), _1E18), XDCBTCPrice, "BUY", "CANCELLED", 3)
time.Sleep(5 * time.Second)
//testSendOrder(t, new(big.Int).SetUint64(48), new(big.Int).SetUint64(15), "SELL", "NEW", 0)
}

View file

@ -346,9 +346,6 @@ func (b *EthAPIBackend) TxPoolContentFrom(addr common.Address) (types.Transactio
func (b *EthAPIBackend) OrderTxPoolContent() (map[common.Address]types.OrderTransactions, map[common.Address]types.OrderTransactions) {
return b.eth.OrderPool().Content()
}
func (b *EthAPIBackend) OrderStats() (pending int, queued int) {
return b.eth.txPool.Stats()
}
func (b *EthAPIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
return b.eth.TxPool().SubscribeNewTxsEvent(ch)

View file

@ -28,7 +28,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/rlp"
"github.com/XinFinOrg/XDPoSChain/rpc"
)
@ -738,27 +737,6 @@ func toBlockNumArg(number *big.Int) string {
return fmt.Sprintf("<invalid %d>", number)
}
// SendOrderTransaction injects a signed transaction into the pending pool for execution.
//
// If the transaction was a contract creation use the TransactionReceipt method to get the
// contract address after the transaction has been mined.
func (ec *Client) SendOrderTransaction(ctx context.Context, tx *types.OrderTransaction) error {
data, err := rlp.EncodeToBytes(tx)
if err != nil {
return err
}
return ec.c.CallContext(ctx, nil, "XDCx_sendOrderRawTransaction", hexutil.Encode(data))
}
// SendLendingTransaction send lending to pool
func (ec *Client) SendLendingTransaction(ctx context.Context, tx *types.LendingTransaction) error {
data, err := rlp.EncodeToBytes(tx)
if err != nil {
return err
}
return ec.c.CallContext(ctx, nil, "XDCx_sendLendingRawTransaction", hexutil.Encode(data))
}
func toCallArg(msg ethereum.CallMsg) interface{} {
arg := map[string]interface{}{
"from": msg.From,

View file

@ -26,8 +26,6 @@ import (
"strings"
"time"
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
"github.com/XinFinOrg/XDPoSChain/accounts"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
"github.com/XinFinOrg/XDPoSChain/common"
@ -1755,12 +1753,6 @@ type TransactionAPI struct {
signer types.Signer
}
// PublicTransactionPoolAPI exposes methods for the RPC interface
type PublicXDCXTransactionPoolAPI struct {
b Backend
nonceLock *AddrLocker
}
// NewTransactionAPI creates a new RPC service with methods specific for the transaction pool.
func NewTransactionAPI(b Backend, nonceLock *AddrLocker) *TransactionAPI {
// The signer used by the API should always be the 'latest' known one because we expect
@ -1769,11 +1761,6 @@ func NewTransactionAPI(b Backend, nonceLock *AddrLocker) *TransactionAPI {
return &TransactionAPI{b, nonceLock, signer}
}
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
func NewPublicXDCXTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicXDCXTransactionPoolAPI {
return &PublicXDCXTransactionPoolAPI{b, nonceLock}
}
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
func (s *TransactionAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint {
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
@ -2068,123 +2055,6 @@ func (s *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.B
return SubmitTransaction(ctx, s.b, tx)
}
// SendOrderRawTransaction will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (s *PublicXDCXTransactionPoolAPI) SendOrderRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
tx := new(types.OrderTransaction)
if err := rlp.DecodeBytes(encodedTx, tx); err != nil {
return common.Hash{}, err
}
return submitOrderTransaction(ctx, s.b, tx)
}
// SendLendingRawTransaction will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (s *PublicXDCXTransactionPoolAPI) SendLendingRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
tx := new(types.LendingTransaction)
if err := rlp.DecodeBytes(encodedTx, tx); err != nil {
return common.Hash{}, err
}
return submitLendingTransaction(ctx, s.b, tx)
}
// GetOrderTxMatchByHash returns the bytes of the transaction for the given hash.
func (s *PublicXDCXTransactionPoolAPI) GetOrderTxMatchByHash(ctx context.Context, hash common.Hash) ([]*tradingstate.OrderItem, error) {
var tx *types.Transaction
orders := []*tradingstate.OrderItem{}
if tx, _, _, _ = rawdb.ReadTransaction(s.b.ChainDb(), hash); tx == nil {
if tx = s.b.GetPoolTransaction(hash); tx == nil {
return []*tradingstate.OrderItem{}, nil
}
}
batch, err := tradingstate.DecodeTxMatchesBatch(tx.Data())
if err != nil {
return []*tradingstate.OrderItem{}, err
}
for _, txMatch := range batch.Data {
order, err := txMatch.DecodeOrder()
if err != nil {
return []*tradingstate.OrderItem{}, err
}
orders = append(orders, order)
}
return orders, nil
}
// GetOrderPoolContent return pending, queued content
func (s *PublicXDCXTransactionPoolAPI) GetOrderPoolContent(ctx context.Context) interface{} {
pendingOrders := []*tradingstate.OrderItem{}
queuedOrders := []*tradingstate.OrderItem{}
pending, queued := s.b.OrderTxPoolContent()
for _, txs := range pending {
for _, tx := range txs {
V, R, S := tx.Signature()
order := &tradingstate.OrderItem{
Nonce: big.NewInt(int64(tx.Nonce())),
Quantity: tx.Quantity(),
Price: tx.Price(),
ExchangeAddress: tx.ExchangeAddress(),
UserAddress: tx.UserAddress(),
BaseToken: tx.BaseToken(),
QuoteToken: tx.QuoteToken(),
Status: tx.Status(),
Side: tx.Side(),
Type: tx.Type(),
Hash: tx.OrderHash(),
OrderID: tx.OrderID(),
Signature: &tradingstate.Signature{
V: byte(V.Uint64()),
R: common.BigToHash(R),
S: common.BigToHash(S),
},
}
pendingOrders = append(pendingOrders, order)
}
}
for _, txs := range queued {
for _, tx := range txs {
V, R, S := tx.Signature()
order := &tradingstate.OrderItem{
Nonce: big.NewInt(int64(tx.Nonce())),
Quantity: tx.Quantity(),
Price: tx.Price(),
ExchangeAddress: tx.ExchangeAddress(),
UserAddress: tx.UserAddress(),
BaseToken: tx.BaseToken(),
QuoteToken: tx.QuoteToken(),
Status: tx.Status(),
Side: tx.Side(),
Type: tx.Type(),
Hash: tx.OrderHash(),
OrderID: tx.OrderID(),
Signature: &tradingstate.Signature{
V: byte(V.Uint64()),
R: common.BigToHash(R),
S: common.BigToHash(S),
},
}
queuedOrders = append(pendingOrders, order)
}
}
return map[string]interface{}{
"pending": pendingOrders,
"queued": queuedOrders,
}
}
// GetOrderStats return pending, queued length
func (s *PublicXDCXTransactionPoolAPI) GetOrderStats(ctx context.Context) interface{} {
pending, queued := s.b.OrderStats()
return map[string]interface{}{
"pending": pending,
"queued": queued,
}
}
// OrderMsg struct
type OrderMsg struct {
AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
@ -2244,667 +2114,6 @@ type InterestVolume struct {
Volume *big.Int `json:"volume,omitempty"`
}
// SendOrder will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (s *PublicXDCXTransactionPoolAPI) SendOrder(ctx context.Context, msg OrderMsg) (common.Hash, error) {
tx := types.NewOrderTransaction(uint64(msg.AccountNonce), msg.Quantity.ToInt(), msg.Price.ToInt(), msg.ExchangeAddress, msg.UserAddress, msg.BaseToken, msg.QuoteToken, msg.Status, msg.Side, msg.Type, msg.Hash, uint64(msg.OrderID))
tx = tx.ImportSignature(msg.V.ToInt(), msg.R.ToInt(), msg.S.ToInt())
return submitOrderTransaction(ctx, s.b, tx)
}
// SendLending will add the signed transaction to the transaction pool.
// The sender is responsible for signing the transaction and using the correct nonce.
func (s *PublicXDCXTransactionPoolAPI) SendLending(ctx context.Context, msg LendingMsg) (common.Hash, error) {
tx := types.NewLendingTransaction(uint64(msg.AccountNonce), msg.Quantity.ToInt(), uint64(msg.Interest), uint64(msg.Term), msg.RelayerAddress, msg.UserAddress, msg.LendingToken, msg.CollateralToken, msg.AutoTopUp, msg.Status, msg.Side, msg.Type, msg.Hash, uint64(msg.LendingId), uint64(msg.LendingTradeId), msg.ExtraData)
tx = tx.ImportSignature(msg.V.ToInt(), msg.R.ToInt(), msg.S.ToInt())
return submitLendingTransaction(ctx, s.b, tx)
}
// GetOrderCount returns the number of transactions the given address has sent for the given block number
func (s *PublicXDCXTransactionPoolAPI) GetOrderCount(ctx context.Context, addr common.Address) (*hexutil.Uint64, error) {
nonce, err := s.b.GetOrderNonce(addr.Hash())
if err != nil {
return (*hexutil.Uint64)(&nonce), err
}
return (*hexutil.Uint64)(&nonce), err
}
func (s *PublicXDCXTransactionPoolAPI) GetBestBid(ctx context.Context, baseToken, quoteToken common.Address) (PriceVolume, error) {
result := PriceVolume{}
block := s.b.CurrentBlock()
if block == nil {
return result, errors.New("current block not found")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return result, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return result, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return result, err
}
result.Price, result.Volume = XDCxState.GetBestBidPrice(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if result.Price.Sign() == 0 {
return result, errors.New("not found bid tree")
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetBestAsk(ctx context.Context, baseToken, quoteToken common.Address) (PriceVolume, error) {
result := PriceVolume{}
block := s.b.CurrentBlock()
if block == nil {
return result, errors.New("not found current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return result, errors.New("not found XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return result, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return result, err
}
result.Price, result.Volume = XDCxState.GetBestAskPrice(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if result.Price.Sign() == 0 {
return result, errors.New("not find ask tree")
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetBidTree(ctx context.Context, baseToken, quoteToken common.Address) (map[*big.Int]tradingstate.DumpOrderList, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
result, err := XDCxState.DumpBidTrie(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetPrice(ctx context.Context, baseToken, quoteToken common.Address) (*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
price := XDCxState.GetLastPrice(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if price == nil || price.Sign() == 0 {
return common.Big0, errors.New("not find order book's price")
}
return price, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLastEpochPrice(ctx context.Context, baseToken, quoteToken common.Address) (*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
price := XDCxState.GetMediumPriceBeforeEpoch(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if price == nil || price.Sign() == 0 {
return common.Big0, errors.New("not find order book's price")
}
return price, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetCurrentEpochPrice(ctx context.Context, baseToken, quoteToken common.Address) (*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
price, _ := XDCxState.GetMediumPriceAndTotalAmount(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if price == nil || price.Sign() == 0 {
return common.Big0, errors.New("not find order book's price")
}
return price, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetAskTree(ctx context.Context, baseToken, quoteToken common.Address) (map[*big.Int]tradingstate.DumpOrderList, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
result, err := XDCxState.DumpAskTrie(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetOrderById(ctx context.Context, baseToken, quoteToken common.Address, orderId uint64) (interface{}, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
orderIdHash := common.BigToHash(new(big.Int).SetUint64(orderId))
orderitem := XDCxState.GetOrder(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken), orderIdHash)
if orderitem.Quantity == nil || orderitem.Quantity.Sign() == 0 {
return nil, errors.New("not found order")
}
return orderitem, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetTradingOrderBookInfo(ctx context.Context, baseToken, quoteToken common.Address) (*tradingstate.DumpOrderBookInfo, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
result, err := XDCxState.DumpOrderBookInfo(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLiquidationPriceTree(ctx context.Context, baseToken, quoteToken common.Address) (map[*big.Int]tradingstate.DumpLendingBook, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
result, err := XDCxState.DumpLiquidationPriceTrie(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetInvestingTree(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]lendingstate.DumpOrderList, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("XDCX Lending service not found")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.DumpInvestingTrie(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetBorrowingTree(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]lendingstate.DumpOrderList, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("XDCX Lending service not found")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.DumpBorrowingTrie(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLendingOrderBookInfo(tx context.Context, lendingToken common.Address, term uint64) (*lendingstate.DumpOrderBookInfo, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("XDCX Lending service not found")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.DumpOrderBookInfo(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) getLendingOrderTree(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]lendingstate.LendingItem, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("not find XDCX Lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.DumpLendingOrderTrie(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLendingTradeTree(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]lendingstate.LendingTrade, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("not find XDCX lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.DumpLendingTradeTrie(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLiquidationTimeTree(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]lendingstate.DumpOrderList, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("not find XDCX Lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.DumpLiquidationTimeTrie(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLendingOrderCount(ctx context.Context, addr common.Address) (*hexutil.Uint64, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("not find XDCX Lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
nonce := lendingState.GetNonce(addr.Hash())
return (*hexutil.Uint64)(&nonce), err
}
func (s *PublicXDCXTransactionPoolAPI) GetBestInvesting(ctx context.Context, lendingToken common.Address, term uint64) (InterestVolume, error) {
result := InterestVolume{}
block := s.b.CurrentBlock()
if block == nil {
return result, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return result, errors.New("not find XDCX Lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return result, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return result, err
}
result.Interest, result.Volume = lendingState.GetBestInvestingRate(lendingstate.GetLendingOrderBookHash(lendingToken, term))
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetBestBorrowing(ctx context.Context, lendingToken common.Address, term uint64) (InterestVolume, error) {
result := InterestVolume{}
block := s.b.CurrentBlock()
if block == nil {
return result, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return result, errors.New("not find XDCX Lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return result, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return result, err
}
result.Interest, result.Volume = lendingState.GetBestBorrowRate(lendingstate.GetLendingOrderBookHash(lendingToken, term))
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetBids(ctx context.Context, baseToken, quoteToken common.Address) (map[*big.Int]*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
result, err := XDCxState.GetBids(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetAsks(ctx context.Context, baseToken, quoteToken common.Address) (map[*big.Int]*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
XDCxService := s.b.XDCxService()
if XDCxService == nil {
return nil, errors.New("not find XDCX service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
XDCxState, err := XDCxService.GetTradingState(block, author)
if err != nil {
return nil, err
}
result, err := XDCxState.GetAsks(tradingstate.GetTradingOrderBookHash(baseToken, quoteToken))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetInvests(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("XDCX Lending service not found")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.GetInvestings(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetBorrows(ctx context.Context, lendingToken common.Address, term uint64) (map[*big.Int]*big.Int, error) {
block := s.b.CurrentBlock()
if block == nil {
return nil, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return nil, errors.New("XDCX Lending service not found")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return nil, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return nil, err
}
result, err := lendingState.GetBorrowings(lendingstate.GetLendingOrderBookHash(lendingToken, term))
if err != nil {
return nil, err
}
return result, nil
}
// GetLendingTxMatchByHash returns lendingItems which have been processed at tx of the given txhash
func (s *PublicXDCXTransactionPoolAPI) GetLendingTxMatchByHash(ctx context.Context, hash common.Hash) ([]*lendingstate.LendingItem, error) {
var tx *types.Transaction
if tx, _, _, _ = rawdb.ReadTransaction(s.b.ChainDb(), hash); tx == nil {
if tx = s.b.GetPoolTransaction(hash); tx == nil {
return []*lendingstate.LendingItem{}, nil
}
}
batch, err := lendingstate.DecodeTxLendingBatch(tx.Data())
if err != nil {
return []*lendingstate.LendingItem{}, err
}
return batch.Data, nil
}
// GetLiquidatedTradesByTxHash returns trades which closed by XDCX protocol at the tx of the give hash
func (s *PublicXDCXTransactionPoolAPI) GetLiquidatedTradesByTxHash(ctx context.Context, hash common.Hash) (lendingstate.FinalizedResult, error) {
var tx *types.Transaction
if tx, _, _, _ = rawdb.ReadTransaction(s.b.ChainDb(), hash); tx == nil {
if tx = s.b.GetPoolTransaction(hash); tx == nil {
return lendingstate.FinalizedResult{}, nil
}
}
finalizedResult, err := lendingstate.DecodeFinalizedResult(tx.Data())
if err != nil {
return lendingstate.FinalizedResult{}, err
}
finalizedResult.TxHash = hash
return finalizedResult, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLendingOrderById(ctx context.Context, lendingToken common.Address, term uint64, orderId uint64) (lendingstate.LendingItem, error) {
lendingItem := lendingstate.LendingItem{}
block := s.b.CurrentBlock()
if block == nil {
return lendingItem, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return lendingItem, errors.New("not find XDCX lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return lendingItem, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return lendingItem, err
}
lendingOrderBook := lendingstate.GetLendingOrderBookHash(lendingToken, term)
orderIdHash := common.BigToHash(new(big.Int).SetUint64(orderId))
lendingItem = lendingState.GetLendingOrder(lendingOrderBook, orderIdHash)
if lendingItem.LendingId != orderId {
return lendingItem, errors.New("not find lending item")
}
return lendingItem, nil
}
func (s *PublicXDCXTransactionPoolAPI) GetLendingTradeById(ctx context.Context, lendingToken common.Address, term uint64, tradeId uint64) (lendingstate.LendingTrade, error) {
lendingItem := lendingstate.LendingTrade{}
block := s.b.CurrentBlock()
if block == nil {
return lendingItem, errors.New("not find current block")
}
lendingService := s.b.LendingService()
if lendingService == nil {
return lendingItem, errors.New("not find XDCX Lending service")
}
author, err := s.b.Engine().Author(block.Header())
if err != nil {
return lendingItem, err
}
lendingState, err := lendingService.GetLendingState(block, author)
if err != nil {
return lendingItem, err
}
lendingOrderBook := lendingstate.GetLendingOrderBookHash(lendingToken, term)
tradeIdHash := common.BigToHash(new(big.Int).SetUint64(tradeId))
lendingItem = lendingState.GetLendingTrade(lendingOrderBook, tradeIdHash)
if lendingItem.TradeId != tradeId {
return lendingItem, errors.New("not find lending item")
}
return lendingItem, nil
}
// Sign calculates an ECDSA signature for:
// keccack256("\x19Ethereum Signed Message:\n" + len(message) + message).
//

View file

@ -93,7 +93,6 @@ type Backend interface {
// Order Pool Transaction
SendOrderTx(ctx context.Context, signedTx *types.OrderTransaction) error
OrderTxPoolContent() (map[common.Address]types.OrderTransactions, map[common.Address]types.OrderTransactions)
OrderStats() (pending int, queued int)
SendLendingTx(ctx context.Context, signedTx *types.LendingTransaction) error
ChainConfig() *params.ChainConfig
@ -135,9 +134,6 @@ func GetAPIs(apiBackend Backend, chainReader consensus.ChainReader) []rpc.API {
}, {
Namespace: "eth",
Service: NewTransactionAPI(apiBackend, nonceLock),
}, {
Namespace: "XDCx",
Service: NewPublicXDCXTransactionPoolAPI(apiBackend, nonceLock),
}, {
Namespace: "txpool",
Service: NewTxPoolAPI(apiBackend),

View file

@ -448,10 +448,6 @@ func (b *backendMock) LendingService() *XDCxlending.Lending {
return nil
}
func (b *backendMock) OrderStats() (int, int) {
return 0, 0
}
func (b *backendMock) OrderTxPoolContent() (map[common.Address]types.OrderTransactions, map[common.Address]types.OrderTransactions) {
return nil, nil
}

View file

@ -18,20 +18,18 @@
package web3ext
var Modules = map[string]string{
"admin": AdminJs,
"chequebook": ChequebookJs,
"clique": CliqueJs,
"XDPoS": XdposJs,
"debug": DebugJs,
"eth": EthJs,
"miner": MinerJs,
"net": NetJs,
"rpc": RpcJs,
"shh": ShhJs,
"XDCx": XdcxJs,
"XDCxlending": XdcxLendingJs,
"swarmfs": SwarmfsJs,
"txpool": TxpoolJs,
"admin": AdminJs,
"chequebook": ChequebookJs,
"clique": CliqueJs,
"XDPoS": XdposJs,
"debug": DebugJs,
"eth": EthJs,
"miner": MinerJs,
"net": NetJs,
"rpc": RpcJs,
"shh": ShhJs,
"swarmfs": SwarmfsJs,
"txpool": TxpoolJs,
}
const ChequebookJs = `
@ -715,326 +713,6 @@ web3._extend({
});
`
const XdcxJs = `
web3._extend({
property: 'XDCx',
methods: [
new web3._extend.Method({
name: 'version',
call: 'XDCx_version',
params: 0,
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Method({
name: 'info',
call: 'XDCx_info',
params: 0
}),
new web3._extend.Method({
name: 'getFeeByEpoch',
call: 'XDCx_getFeeByEpoch',
params: 1,
inputFormatter: [null, web3._extend.formatters.inputAddressFormatter]
}),
new web3._extend.Method({
name: 'sendOrderRawTransaction',
call: 'XDCx_sendOrderRawTransaction',
params: 1
}),
new web3._extend.Method({
name: 'sendLendingRawTransaction',
call: 'XDCx_sendLendingRawTransaction',
params: 1
}),
new web3._extend.Method({
name: 'sendOrderTransaction',
call: 'XDCx_sendOrder',
params: 1
}),
new web3._extend.Method({
name: 'sendLendingTransaction',
call: 'XDCx_sendLending',
params: 1
}),
new web3._extend.Method({
name: 'getOrderTxMatchByHash',
call: 'XDCx_getOrderTxMatchByHash',
params: 1
}),
new web3._extend.Method({
name: 'getOrderPoolContent',
call: 'XDCx_getOrderPoolContent',
params: 0
}),
new web3._extend.Method({
name: 'getOrderStats',
call: 'XDCx_getOrderStats',
params: 0
}),
new web3._extend.Method({
name: 'getOrderCount',
call: 'XDCx_getOrderCount',
params: 1
}),
new web3._extend.Method({
name: 'getBestBid',
call: 'XDCx_getBestBid',
params: 2
}),
new web3._extend.Method({
name: 'getBestAsk',
call: 'XDCx_getBestAsk',
params: 2
}),
new web3._extend.Method({
name: 'getBidTree',
call: 'XDCx_getBidTree',
params: 2
}),
new web3._extend.Method({
name: 'getAskTree',
call: 'XDCx_getAskTree',
params: 2
}),
new web3._extend.Method({
name: 'getOrderById',
call: 'XDCx_getOrderById',
params: 3
}),
new web3._extend.Method({
name: 'getPrice',
call: 'XDCx_getPrice',
params: 2
}),
new web3._extend.Method({
name: 'getLastEpochPrice',
call: 'XDCx_getLastEpochPrice',
params: 2
}),
new web3._extend.Method({
name: 'getCurrentEpochPrice',
call: 'XDCx_getCurrentEpochPrice',
params: 2
}),
new web3._extend.Method({
name: 'getTradingOrderBookInfo',
call: 'XDCx_getTradingOrderBookInfo',
params: 2
}),
new web3._extend.Method({
name: 'getLiquidationPriceTree',
call: 'XDCx_getLiquidationPriceTree',
params: 2
}),
new web3._extend.Method({
name: 'getInvestingTree',
call: 'XDCx_getInvestingTree',
params: 2
}),
new web3._extend.Method({
name: 'getBorrowingTree',
call: 'XDCx_getBorrowingTree',
params: 2
}),
new web3._extend.Method({
name: 'getLendingOrderBookInfo',
call: 'XDCx_getLendingOrderBookInfo',
params: 2
}),
new web3._extend.Method({
name: 'getLendingOrderTree',
call: 'XDCx_getLendingOrderTree',
params: 2
}),
new web3._extend.Method({
name: 'getLendingTradeTree',
call: 'XDCx_getLendingTradeTree',
params: 2
}),
new web3._extend.Method({
name: 'getLiquidationTimeTree',
call: 'XDCx_getLiquidationTimeTree',
params: 2
}),
new web3._extend.Method({
name: 'getLendingOrderCount',
call: 'XDCx_getLendingOrderCount',
params: 1
}),
new web3._extend.Method({
name: 'getBestInvesting',
call: 'XDCx_getBestInvesting',
params: 2
}),
new web3._extend.Method({
name: 'getBestBorrowing',
call: 'XDCx_getBestBorrowing',
params: 2
}),
new web3._extend.Method({
name: 'getBids',
call: 'XDCx_getBids',
params: 2
}),
new web3._extend.Method({
name: 'getAsks',
call: 'XDCx_getAsks',
params: 2
}),
new web3._extend.Method({
name: 'getInvests',
call: 'XDCx_getInvests',
params: 2
}),
new web3._extend.Method({
name: 'getBorrows',
call: 'XDCx_getBorrows',
params: 2
}),
new web3._extend.Method({
name: 'getLendingTxMatchByHash',
call: 'XDCx_getLendingTxMatchByHash',
params: 1
}),
new web3._extend.Method({
name: 'getLiquidatedTradesByTxHash',
call: 'XDCx_getLiquidatedTradesByTxHash',
params: 1
}),
new web3._extend.Method({
name: 'getLendingOrderById',
call: 'XDCx_getLendingOrderById',
params: 3
}),
new web3._extend.Method({
name: 'getLendingTradeById',
call: 'XDCx_getLendingTradeById',
params: 3
}),
]
});
`
const XdcxLendingJs = `
web3._extend({
property: 'XDCxlending',
methods: [
new web3._extend.Method({
name: 'version',
call: 'XDCxlending_version',
params: 0,
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Method({
name: 'info',
call: 'XDCxlending_info',
params: 0
}),
new web3._extend.Method({
name: 'createOrder',
call: 'XDCxlending_createOrder',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'cancelOrder',
call: 'XDCxlending_cancelOrder',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'getOrders',
call: 'XDCxlending_getOrders',
params: 1
}),
new web3._extend.Method({
name: 'getOrderNonce',
call: 'XDCxlending_getOrderNonce',
params: 1,
inputFormatter: [web3._extend.formatters.inputAddressFormatter]
}),
new web3._extend.Method({
name: 'getFeeByEpoch',
call: 'XDCxlending_GetFeeByEpoch',
params: 1,
inputFormatter: [null, web3._extend.formatters.inputAddressFormatter]
}),
new web3._extend.Method({
name: 'getPendingOrders',
call: 'XDCxlending_getPendingOrders',
params: 1
}),
new web3._extend.Method({
name: 'getAllPendingHashes',
call: 'XDCxlending_getAllPendingHashes',
params: 0
}),
new web3._extend.Method({
name: 'sendOrderRawTransaction',
call: 'XDCxlending_sendOrderRawTransaction',
params: 1
}),
new web3._extend.Method({
name: 'sendOrderTransaction',
call: 'XDCxlending_sendOrder',
params: 1
}),
new web3._extend.Method({
name: 'getOrderCount',
call: 'XDCxlending_getOrderCount',
params: 1
}),
new web3._extend.Method({
name: 'getBestBid',
call: 'XDCxlending_getBestBid',
params: 2
}),
new web3._extend.Method({
name: 'getBestAsk',
call: 'XDCxlending_getBestAsk',
params: 2
}),
new web3._extend.Method({
name: 'getBidTree',
call: 'XDCxlending_getBidTree',
params: 2
}),
new web3._extend.Method({
name: 'getAskTree',
call: 'XDCxlending_getAskTree',
params: 2
}),
new web3._extend.Method({
name: 'getOrderById',
call: 'XDCxlending_getOrderById',
params: 3
}),
new web3._extend.Method({
name: 'getPrice',
call: 'XDCxlending_getPrice',
params: 2
}),
]
});
`
/*
var sendOrderRawTransaction = new Method({
name: 'sendOrderRawTransaction',
call: 'eth_sendOrderRawTransaction',
params: 1,
inputFormatter: [null]
});
var sendOrderTransaction = new Method({
name: 'sendOrder',
call: 'XDCx_sendOrder',
params: 1,
inputFormatter: [null]
});
*/
const SwarmfsJs = `
web3._extend({
property: 'swarmfs',