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

Remove party id from withdrawal submission #3449

Merged
merged 1 commit into from
May 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions accounts/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
)

var (
// ErrMissingPartyID signals that the payload is expected to contain a party id
ErrMissingPartyID = errors.New("missing party id")
// usually the party specified an amount of 0
// ErrInvalidWithdrawAmount usually the party specified an amount of 0
ErrInvalidWithdrawAmount = errors.New("invalid withdraw amount (must be > 0)")
// ErrMissingAsset signals that an asset was required but not specified
ErrMissingAsset = errors.New("missing asset")
Expand Down Expand Up @@ -65,9 +63,6 @@ func (s *Svc) ReloadConf(cfg Config) {
}

func (s *Svc) PrepareWithdraw(ctx context.Context, w *commandspb.WithdrawSubmission) error {
if len(w.PartyId) <= 0 {
return ErrMissingPartyID
}
if len(w.Asset) <= 0 {
return ErrMissingAsset
}
Expand Down
34 changes: 12 additions & 22 deletions gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions gateway/graphql/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ type myMutationResolver VegaResolverRoot

func (r *myMutationResolver) PrepareWithdrawal(
ctx context.Context,
partyID, amount, asset string,
amount, asset string,
erc20Details *Erc20WithdrawalDetailsInput,
) (*PreparedWithdrawal, error) {
var ext *types.WithdrawExt
Expand All @@ -1605,10 +1605,9 @@ func (r *myMutationResolver) PrepareWithdrawal(

req := protoapi.PrepareWithdrawRequest{
Withdraw: &commandspb.WithdrawSubmission{
PartyId: partyID,
Asset: asset,
Amount: amountU,
Ext: ext,
Asset: asset,
Amount: amountU,
Ext: ext,
},
}

Expand Down
2 changes: 0 additions & 2 deletions gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ type Mutation {
Returns a pending withdrawSubmission with a transaction blob for signing.
"""
prepareWithdrawal(
"The party which wants to withdraw funds"
partyId: ID!
"The amount to be withdrawn"
amount: String!
"The asset from which we want to withdraw funds"
Expand Down
2 changes: 1 addition & 1 deletion processor/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (app *App) DeliverWithdraw(
return err
}

return app.processWithdraw(ctx, w, id)
return app.processWithdraw(ctx, w, id, tx.Party())
}

func (app *App) DeliverPropose(ctx context.Context, tx abci.Tx, id string) error {
Expand Down
9 changes: 4 additions & 5 deletions processor/process_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ var (
ErrMissingWithdrawERC20Ext = errors.New("missing withdraw submission erc20 ext")
)

func (app *App) processWithdraw(ctx context.Context, w *commandspb.WithdrawSubmission, id string) error {
func (app *App) processWithdraw(ctx context.Context, w *commandspb.WithdrawSubmission, id string, party string) error {
asset, err := app.assets.Get(w.Asset)
if err != nil {
app.log.Error("invalid vega asset ID for withdrawal",
logging.Error(err),
logging.String("party-id", w.PartyId),
logging.Uint64("amount", w.Amount),
logging.String("asset-id", w.Asset))
logging.AssetID(w.Asset))
return err
}

switch {
case asset.IsBuiltinAsset():
return app.banking.WithdrawalBuiltinAsset(ctx, id, w.PartyId, w.Asset, w.Amount)
return app.banking.WithdrawalBuiltinAsset(ctx, id, party, w.Asset, w.Amount)
case asset.IsERC20():
ext := w.Ext.GetErc20()
if ext == nil {
return ErrMissingWithdrawERC20Ext
}
return app.banking.LockWithdrawalERC20(ctx, id, w.PartyId, w.Asset, w.Amount, ext)
return app.banking.LockWithdrawalERC20(ctx, id, party, w.Asset, w.Amount, ext)
}

return errors.New("unimplemented withdrawal")
Expand Down
6 changes: 0 additions & 6 deletions processor/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ func (s *TxTestSuite) testValidateCommandSuccess(t *testing.T) {
txn.VoteCommand: &types.Vote{
PartyId: party,
},
txn.WithdrawCommand: &commandspb.WithdrawSubmission{
PartyId: party,
},
txn.ProposeCommand: &types.Proposal{
PartyId: party,
},
Expand Down Expand Up @@ -85,9 +82,6 @@ func (s *TxTestSuite) testValidateCommandsFail(t *testing.T) {
txn.AmendOrderCommand: &commandspb.OrderAmendment{
PartyId: party,
},
txn.WithdrawCommand: &commandspb.WithdrawSubmission{
PartyId: party,
},
}

for cmd, msg := range msgs {
Expand Down
4 changes: 0 additions & 4 deletions proto/api/trading.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3510,10 +3510,6 @@
"v1WithdrawSubmission": {
"type": "object",
"properties": {
"party_id": {
"type": "string",
"title": "Unique party identifier for the user wanting to withdraw funds"
},
"amount": {
"type": "string",
"format": "uint64",
Expand Down