Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add back some deposit / withdrawal logic removed from the merges #2437

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion banking/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math/big"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -433,7 +434,8 @@ func (e *Engine) finalizeAction(ctx context.Context, aa *assetAction) error {
case aa.IsERC20Deposit():
// here the event queue send us a 0x... pubkey
// we do the slice operation to remove it ([2:]
aa.deposit.partyID = aa.deposit.partyID[2:]

aa.deposit.partyID = strings.TrimPrefix(aa.deposit.partyID, "0x")
return e.finalizeDeposit(ctx, aa.deposit, aa.id)
case aa.IsERC20AssetList():
return e.finalizeAssetList(ctx, aa.erc20AL.VegaAssetID)
Expand Down Expand Up @@ -472,6 +474,7 @@ func (e *Engine) getWithdrawalFromRef(ref *big.Int) (*types.Withdrawal, error) {

func (e *Engine) finalizeDeposit(ctx context.Context, d *deposit, id string) error {
dep := e.deposits[id]
dep.Amount = fmt.Sprintf("%v", d.amount)
dep.Status = types.Deposit_DEPOSIT_STATUS_FINALIZED
e.broker.Send(events.NewDepositEvent(ctx, *dep))
return e.col.Deposit(ctx, d.partyID, d.assetID, d.amount)
Expand Down Expand Up @@ -501,6 +504,8 @@ func (e *Engine) finalizeAssetList(ctx context.Context, assetID string) error {
}

func (e *Engine) newWithdrawal(partyID, asset string, amount uint64, expiry time.Time, now time.Time, wext *types.WithdrawExt) (w *types.Withdrawal, ref *big.Int) {
partyID = strings.TrimPrefix(partyID, "0x")
asset = strings.TrimPrefix(asset, "0x")
w = &types.Withdrawal{
Status: types.Withdrawal_WITHDRAWAL_STATUS_OPEN,
PartyID: partyID,
Expand All @@ -515,6 +520,8 @@ func (e *Engine) newWithdrawal(partyID, asset string, amount uint64, expiry time

func (e *Engine) newDeposit(partyID, asset string, amount uint64) (d *types.Deposit) {
now, _ := e.tsvc.GetTimeNow()
partyID = strings.TrimPrefix(partyID, "0x")
asset = strings.TrimPrefix(asset, "0x")
d = &types.Deposit{
Status: types.Deposit_DEPOSIT_STATUS_OPEN,
PartyID: partyID,
Expand Down
26 changes: 13 additions & 13 deletions plugins/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,31 @@ func (w *Deposit) consume() {
}
}

func (w *Deposit) GetByID(id string) (types.Deposit, error) {
w.mu.RLock()
defer w.mu.RUnlock()
func (d *Deposit) GetByID(id string) (types.Deposit, error) {
d.mu.RLock()
defer d.mu.RUnlock()
// FIXME(jeremy): this is very naive, and will require
// a lookup table over the dephposit id -> party
for _, deposits := range w.deposits {
for wid, deposit := range deposits {
if wid == id {
for _, deposits := range d.deposits {
for did, deposit := range deposits {
if did == id {
return deposit, nil
}
}
}
return types.Deposit{}, ErrNoDepositForID
}

func (w *Deposit) GetByParty(party string, openOnly bool) []types.Deposit {
w.mu.RLock()
defer w.mu.RUnlock()
func (d *Deposit) GetByParty(party string, openOnly bool) []types.Deposit {
d.mu.RLock()
defer d.mu.RUnlock()
out := []types.Deposit{}
deposits := w.deposits[party]
for _, w := range deposits {
if openOnly && w.Status != types.Deposit_DEPOSIT_STATUS_OPEN {
deposits := d.deposits[party]
for _, dep := range deposits {
if openOnly && dep.Status != types.Deposit_DEPOSIT_STATUS_OPEN {
continue
}
out = append(out, w)
out = append(out, dep)
}
return out
}
Expand Down
13 changes: 10 additions & 3 deletions processor/process_chain_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package processor
import (
"context"
"errors"
"strings"

"code.vegaprotocol.io/vega/logging"
types "code.vegaprotocol.io/vega/proto"
Expand Down Expand Up @@ -38,7 +39,7 @@ func (app *App) processChainEvent(ctx context.Context, ce *types.ChainEvent, pub
case *types.ChainEvent_Btc:
return errors.New("BTC Event not implemented")
case *types.ChainEvent_Validator:
return errors.New("Validator Event not implemented")
return errors.New("validator Event not implemented")
default:
return ErrUnsupportedChainEvent
}
Expand Down Expand Up @@ -88,12 +89,18 @@ func (app *App) processChainEventERC20(ctx context.Context, ce *types.ChainEvent
case *types.ERC20Event_AssetDelist:
return errors.New("ERC20.AssetDelist not implemented")
case *types.ERC20Event_Deposit:
if err := app.checkVegaAssetID(act.Deposit, "ERC20.AssetList"); err != nil {
act.Deposit.VegaAssetID = strings.TrimPrefix(act.Deposit.VegaAssetID, "0x")

if err := app.checkVegaAssetID(act.Deposit, "ERC20.AssetDeposit"); err != nil {
return err
}
return app.banking.DepositERC20(ctx, act.Deposit, evt.Block, evt.Index)
case *types.ERC20Event_Withdrawal:
return errors.New("ERC20.Withdrawal not implemented")
act.Withdrawal.VegaAssetID = strings.TrimPrefix(act.Withdrawal.VegaAssetID, "0x")
if err := app.checkVegaAssetID(act.Withdrawal, "ERC20.AssetWithdrawal"); err != nil {
return err
}
return app.banking.WithdrawalERC20(act.Withdrawal, evt.Block, evt.Index)
default:
return ErrUnsupportedEventAction
}
Expand Down