Skip to content

Commit

Permalink
Fix: merging swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jan 20, 2022
1 parent d4b78e1 commit f8f4458
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/watch_tower/watch_tower.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func NewWatchTower(cfg Config) (*WatchTower, error) {
operations: make(map[tools.OperationID]chain.Operation),
swaps: make(map[chain.Hex]*Swap),
}
if wt.retryCount == 0 {
wt.retryCount = 3
}

for i := range cfg.Types {
switch cfg.Types[i] {
Expand Down Expand Up @@ -99,6 +102,8 @@ func (wt *WatchTower) listen(ctx context.Context) {
if !ok {
s = &Swap{swap, 0}
wt.swaps[swap.HashedSecret] = s
} else {
s.Swap = swap
}

if err := wt.onSwap(ctx, s); err != nil {
Expand Down
12 changes: 8 additions & 4 deletions internal/chain/tezos/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,18 @@ func (t *Tezos) restoreFinilizationSwap(ctx context.Context, bm api.BigMap, key
if err != nil {
return err
}
decodedKey, err := hex.DecodeString(key.Key)
if err != nil {
return err
}

for i := range updates {
if t.cfg.Contract == bm.Contract.Address {
var bmUpdate atomextez.BigMapUpdate
if err := json.Unmarshal(updates[i].Value, &bmUpdate.BigMap.Value); err != nil {
return err
}
bmUpdate.BigMap.Key = atomextez.KeyBigMap(key.Key)
bmUpdate.BigMap.Key = atomextez.KeyBigMap(decodedKey)
bmUpdate.BigMap.Ptr = &bm.Ptr
bmUpdate.Action = updates[i].Action
bmUpdate.Contract = bm.Contract.Address
Expand All @@ -494,7 +498,7 @@ func (t *Tezos) restoreFinilizationSwap(ctx context.Context, bm api.BigMap, key
if err := json.Unmarshal(updates[i].Value, &bmUpdate.BigMap0.Value); err != nil {
return err
}
bmUpdate.BigMap0.Key = atomexteztoken.Key0(key.Key)
bmUpdate.BigMap0.Key = atomexteztoken.Key0(decodedKey)
bmUpdate.BigMap0.Ptr = &bm.Ptr
bmUpdate.Action = updates[i].Action
bmUpdate.Contract = bm.Contract.Address
Expand All @@ -508,7 +512,7 @@ func (t *Tezos) restoreFinilizationSwap(ctx context.Context, bm api.BigMap, key
}

func (t *Tezos) parseTezosContractUpdate(ctx context.Context, update atomextez.BigMapUpdate) error {
hashedSecret := chain.Hex(update.BigMap.Key)
hashedSecret := chain.NewHexFromBytes(update.BigMap.Key)

switch update.Action {
case BigMapActionAddKey:
Expand Down Expand Up @@ -579,7 +583,7 @@ func (t *Tezos) parseTezosContractUpdate(ctx context.Context, update atomextez.B
}

func (t *Tezos) parseTokenContractUpdate(ctx context.Context, update atomexteztoken.BigMap0Update) error {
hashedSecret := chain.Hex(update.BigMap0.Key)
hashedSecret := chain.NewHexFromBytes(update.BigMap0.Key)

switch update.Action {
case BigMapActionAddKey:
Expand Down

0 comments on commit f8f4458

Please sign in to comment.