mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-10 06:38:04 -05:00
add relayer fee to swapcli past (#474)
This commit is contained in:
@@ -896,11 +896,27 @@ func runGetPastSwap(ctx *cli.Context) error {
|
||||
endTime = info.EndTime.Format(common.TimeFmtSecs)
|
||||
}
|
||||
|
||||
receivedAmt := info.ExpectedAmount
|
||||
if info.RelayerFee != nil {
|
||||
receivedAmt = new(apd.Decimal)
|
||||
_, err = coins.DecimalCtx().Sub(receivedAmt, info.ExpectedAmount, info.RelayerFee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("ID: %s\n", info.ID)
|
||||
fmt.Printf("Start time: %s\n", info.StartTime.Format(common.TimeFmtSecs))
|
||||
fmt.Printf("End time: %s\n", endTime)
|
||||
fmt.Printf("Provided: %s %s\n", info.ProvidedAmount.Text('f'), providedCoin)
|
||||
fmt.Printf("Received: %s %s\n", info.ExpectedAmount.Text('f'), receivedCoin)
|
||||
fmt.Printf("Received: %s %s", receivedAmt.Text('f'), receivedCoin)
|
||||
if info.RelayerFee != nil {
|
||||
fmt.Printf(" (%s %s - %s %s relayer fee)",
|
||||
info.ExpectedAmount.Text('f'), receivedCoin,
|
||||
info.RelayerFee.Text('f'), receivedCoin,
|
||||
)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Exchange Rate: %s ETH/XMR\n", info.ExchangeRate)
|
||||
fmt.Printf("Status: %s\n", info.Status)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ type Info struct {
|
||||
Provides coins.ProvidesCoin `json:"provides" validate:"required"`
|
||||
ProvidedAmount *apd.Decimal `json:"providedAmount" validate:"required"`
|
||||
ExpectedAmount *apd.Decimal `json:"expectedAmount" validate:"required"`
|
||||
RelayerFee *apd.Decimal `json:"relayerFee,omitempty"`
|
||||
ExchangeRate *coins.ExchangeRate `json:"exchangeRate" validate:"required"`
|
||||
EthAsset types.EthAsset `json:"ethAsset"`
|
||||
Status Status `json:"status" validate:"required"`
|
||||
@@ -138,6 +139,14 @@ func (i *Info) MarkSwapComplete() {
|
||||
i.EndTime = &now
|
||||
}
|
||||
|
||||
// SetRelayerFee updates the RelayerFee field
|
||||
func (i *Info) SetRelayerFee(relayerFee *apd.Decimal) {
|
||||
i.rwMu.Lock()
|
||||
defer i.rwMu.Unlock()
|
||||
|
||||
i.RelayerFee = relayerFee
|
||||
}
|
||||
|
||||
// IsTaker returns true if the node is the xmr-taker in the swap.
|
||||
func (i *Info) IsTaker() bool {
|
||||
return i.Provides == coins.ProvidesETH
|
||||
|
||||
@@ -235,8 +235,20 @@ func (s *swapState) claimWithRelay() (*ethtypes.Receipt, error) {
|
||||
if err != nil {
|
||||
log.Warnf("failed to relay with DHT-advertised relayers: %s", err)
|
||||
log.Infof("falling back to swap counterparty as relayer")
|
||||
return s.relayClaimWithXMRTaker()
|
||||
receipt, err = s.relayClaimWithXMRTaker()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Save the relayer fee to the database
|
||||
s.info.SetRelayerFee(coins.RelayerFeeETH)
|
||||
swapManager := s.SwapManager()
|
||||
err = swapManager.WriteSwapToDB(s.info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return receipt, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ type PastSwap struct {
|
||||
EthAsset types.EthAsset `json:"ethAsset"`
|
||||
ProvidedAmount *apd.Decimal `json:"providedAmount" validate:"required"`
|
||||
ExpectedAmount *apd.Decimal `json:"expectedAmount" validate:"required"`
|
||||
RelayerFee *apd.Decimal `json:"relayerFee"`
|
||||
ExchangeRate *coins.ExchangeRate `json:"exchangeRate" validate:"required"`
|
||||
Status types.Status `json:"status" validate:"required"`
|
||||
StartTime time.Time `json:"startTime" validate:"required"`
|
||||
@@ -113,6 +114,7 @@ func (s *SwapService) GetPast(_ *http.Request, req *GetPastRequest, resp *GetPas
|
||||
EthAsset: info.EthAsset,
|
||||
ProvidedAmount: info.ProvidedAmount,
|
||||
ExpectedAmount: info.ExpectedAmount,
|
||||
RelayerFee: info.RelayerFee,
|
||||
ExchangeRate: info.ExchangeRate,
|
||||
Status: info.Status,
|
||||
StartTime: info.StartTime,
|
||||
|
||||
Reference in New Issue
Block a user