Skip to content

Commit

Permalink
Remove write lock option from the avm wallet API (#2155)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Oct 11, 2023
1 parent e6dab5d commit 0f95f13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vms/avm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]*common.HTTPHandler, e

return map[string]*common.HTTPHandler{
"": {Handler: rpcServer},
"/wallet": {Handler: walletServer},
"/wallet": {LockOptions: common.NoLock, Handler: walletServer},
"/events": {LockOptions: common.NoLock, Handler: vm.pubsub},
}, err
}
Expand Down
7 changes: 7 additions & 0 deletions vms/avm/wallet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (w *WalletService) IssueTx(_ *http.Request, args *api.FormattedTx, reply *a
if err != nil {
return fmt.Errorf("problem decoding transaction: %w", err)
}

w.vm.ctx.Lock.Lock()
defer w.vm.ctx.Lock.Unlock()

txID, err := w.issue(txBytes)
reply.TxID = txID
return err
Expand Down Expand Up @@ -179,6 +183,9 @@ func (w *WalletService) SendMultiple(_ *http.Request, args *SendMultipleArgs, re
return fmt.Errorf("couldn't parse 'From' addresses: %w", err)
}

w.vm.ctx.Lock.Lock()
defer w.vm.ctx.Lock.Unlock()

// Load user's UTXOs/keys
utxos, kc, err := w.vm.LoadUser(args.Username, args.Password, fromAddrs)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions vms/avm/wallet_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestWalletService_SendMultiple(t *testing.T) {
initialKeys: keys,
}},
})
env.vm.ctx.Lock.Unlock()

defer func() {
require.NoError(env.vm.Shutdown(context.Background()))
env.vm.ctx.Lock.Unlock()
Expand Down Expand Up @@ -65,6 +67,8 @@ func TestWalletService_SendMultiple(t *testing.T) {
require.NoError(env.walletService.SendMultiple(nil, args, reply))
require.Equal(changeAddrStr, reply.ChangeAddr)

env.vm.ctx.Lock.Lock()

buildAndAccept(require, env.vm, env.issuer, reply.TxID)

_, err = env.vm.state.GetTx(reply.TxID)
Expand Down

0 comments on commit 0f95f13

Please sign in to comment.