Skip to content

Commit

Permalink
Merge pull request #13 from perun-network:refactor-client-mutex
Browse files Browse the repository at this point in the history
Remove global mutex from client package, in favor of a mutex in the Client struct.
  • Loading branch information
iljabvh committed Apr 16, 2024
2 parents c5676b8 + 4d7bc49 commit fea237f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/stellar/go/keypair"
"github.com/stellar/go/xdr"
"log"

pchannel "perun.network/go-perun/channel"
pwallet "perun.network/go-perun/wallet"
"sync"

"perun.network/perun-stellar-backend/event"
"perun.network/perun-stellar-backend/wire"
Expand All @@ -36,6 +36,7 @@ var ErrCouldNotDecodeTxMeta = errors.New("could not decode tx output")
type Client struct {
hzClient *horizonclient.Client
keyHolder keyHolder
mtx sync.Mutex
}
type keyHolder struct {
kp *keypair.Full
Expand All @@ -45,6 +46,7 @@ func New(kp *keypair.Full) *Client {
return &Client{
hzClient: NewHorizonClient(),
keyHolder: newKeyHolder(kp),
mtx: sync.Mutex{},
}
}

Expand Down
7 changes: 2 additions & 5 deletions client/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import (
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"strconv"
"sync"
"time"
)

var sharedMtx sync.Mutex

const sorobanRPCPort = 8000

func (s *Client) CreateSignedTxFromParams(txParams txnbuild.TransactionParams) (*txnbuild.Transaction, error) {
Expand Down Expand Up @@ -50,8 +47,8 @@ func CreateSignedTransactionWithParams(signers []*keypair.Full, txParams txnbuil
}

func (c *Client) InvokeAndProcessHostFunction(fname string, callTxArgs xdr.ScVec, contractAddr xdr.ScAddress) (xdr.TransactionMeta, error) {
sharedMtx.Lock()
defer sharedMtx.Unlock()
c.mtx.Lock()
defer c.mtx.Unlock()
fnameXdr := xdr.ScSymbol(fname)
hzAcc, err := c.GetHorizonAccount()
if err != nil {
Expand Down

0 comments on commit fea237f

Please sign in to comment.