generated from KyberNetwork/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from KyberNetwork/zxrfq
zxrfq
- Loading branch information
Showing
14 changed files
with
1,086 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "string", | ||
"name": "source", | ||
"type": "string" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "bytes32", | ||
"name": "transactionHash", | ||
"type": "bytes32" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "bytes32", | ||
"name": "orderHash", | ||
"type": "bytes32" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "userAddr", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "takerAssetAddr", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "takerAssetAmount", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "makerAddr", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "makerAssetAddr", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "makerAssetAmount", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "receiverAddr", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "settleAmount", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint16", | ||
"name": "feeFactor", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "FillOrder", | ||
"type": "event" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abigen --abi=abi.json --pkg=tokenlon --out=tokenlon.go -type FillOrder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package tokenlon | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/KyberNetwork/tradelogs/internal/storage" | ||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
const ( | ||
FillOrderEvent = "FillOrder" | ||
) | ||
|
||
var ErrInvalidRFQTopic = errors.New("invalid RfqFilled topic") | ||
|
||
type Parser struct { | ||
abi *abi.ABI | ||
ps *FillOrderFilterer | ||
eventHash string | ||
} | ||
|
||
func MustNewParser() *Parser { | ||
ps, err := NewFillOrderFilterer(common.Address{}, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ab, err := FillOrderMetaData.GetAbi() | ||
if err != nil { | ||
panic(err) | ||
} | ||
event, ok := ab.Events[FillOrderEvent] | ||
if !ok { | ||
panic("no such event: FillOrder") | ||
} | ||
return &Parser{ | ||
ps: ps, | ||
abi: ab, | ||
eventHash: event.ID.String(), | ||
} | ||
} | ||
|
||
func (p *Parser) Topics() []string { | ||
return []string{ | ||
p.eventHash, | ||
} | ||
} | ||
|
||
func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error) { | ||
if len(log.Topics) > 0 && log.Topics[0].Hex() != p.eventHash { | ||
return storage.TradeLog{}, ErrInvalidRFQTopic | ||
} | ||
o, err := p.ps.ParseFillOrder(log) | ||
if err != nil { | ||
return storage.TradeLog{}, err | ||
} | ||
res := storage.TradeLog{ | ||
OrderHash: common.Hash(o.OrderHash).String(), | ||
Maker: o.MakerAddr.Hex(), | ||
Taker: o.ReceiverAddr.Hex(), | ||
MakerToken: o.MakerAssetAddr.Hex(), | ||
TakerToken: o.TakerAssetAddr.Hex(), | ||
MakerTokenAmount: o.MakerAssetAmount.String(), | ||
TakerTokenAmount: o.SettleAmount.String(), | ||
ContractAddress: o.Raw.Address.String(), | ||
BlockNumber: o.Raw.BlockNumber, | ||
TxHash: o.Raw.TxHash.String(), | ||
LogIndex: uint64(o.Raw.Index), | ||
Timestamp: blockTime * 1000, | ||
} | ||
return res, nil | ||
} |
Oops, something went wrong.