terra: include block timestamp in VAAs (#94)

Fixes #93
This commit is contained in:
Yuriy Savchenko 2020-11-18 20:16:29 +02:00 committed by GitHub
parent bbf479871f
commit 84600ad9f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -102,9 +102,10 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
amount := gjson.Get(json, "result.events.from_contract\\.locked\\.amount.0")
nonce := gjson.Get(json, "result.events.from_contract\\.locked\\.nonce.0")
txHash := gjson.Get(json, "result.events.tx\\.hash.0")
blockTime := gjson.Get(json, "result.events.from_contract\\.locked\\.block_time.0")
if targetChain.Exists() && tokenChain.Exists() && tokenDecimals.Exists() && token.Exists() &&
sender.Exists() && recipient.Exists() && amount.Exists() && amount.Exists() && nonce.Exists() && txHash.Exists() {
if targetChain.Exists() && tokenChain.Exists() && tokenDecimals.Exists() && token.Exists() && sender.Exists() &&
recipient.Exists() && amount.Exists() && amount.Exists() && nonce.Exists() && txHash.Exists() && blockTime.Exists() {
logger.Info("token lock detected on Terra",
zap.String("txHash", txHash.String()),
@ -115,7 +116,9 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
zap.String("sender", sender.String()),
zap.String("recipient", recipient.String()),
zap.String("amount", amount.String()),
zap.String("nonce", nonce.String()))
zap.String("nonce", nonce.String()),
zap.String("blockTime", blockTime.String()),
)
senderAddress, err := StringToAddress(sender.String())
if err != nil {
@ -139,7 +142,7 @@ func (e *BridgeWatcher) Run(ctx context.Context) error {
}
lock := &common.ChainLock{
TxHash: txHashValue,
Timestamp: time.Now(), // No timestamp available, consider adding it into transaction logs or request additionally from the blockchain
Timestamp: time.Unix(blockTime.Int(), 0),
Nonce: uint32(nonce.Uint()),
SourceAddress: senderAddress,
TargetAddress: recipientAddress,

View File

@ -478,6 +478,7 @@ fn handle_lock_assets<S: Storage, A: Api, Q: Querier>(
log("locked.recipient", hex::encode(recipient)),
log("locked.amount", amount),
log("locked.nonce", nonce),
log("locked.block_time", env.block.time),
],
data: None,
})