Skip to content

Commit 04d914c

Browse files
committed
rfq: refactor mock price calculation
The variable name was incorrect in the first place, so we fix that to properly represent how the mock price is currently interpreted. And to allow for different ways of specifying a mock price, we move the static calculation to the constructor.
1 parent 0fd548f commit 04d914c

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

rfq/oracle.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,18 @@ var _ PriceOracle = (*RpcPriceOracle)(nil)
368368
// MockPriceOracle is a mock implementation of the PriceOracle interface.
369369
// It returns the suggested rate as the exchange rate.
370370
type MockPriceOracle struct {
371-
expiryDelay uint64
372-
usdPerBTC uint64
371+
expiryDelay uint64
372+
mSatPerAsset lnwire.MilliSatoshi
373373
}
374374

375375
// NewMockPriceOracle creates a new mock price oracle.
376-
func NewMockPriceOracle(expiryDelay, usdPerBTC uint64) *MockPriceOracle {
376+
func NewMockPriceOracle(expiryDelay, assetsPerBTC uint64) *MockPriceOracle {
377+
mSatPerAsset := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) /
378+
lnwire.MilliSatoshi(assetsPerBTC)
379+
377380
return &MockPriceOracle{
378-
expiryDelay: expiryDelay,
379-
usdPerBTC: usdPerBTC,
381+
expiryDelay: expiryDelay,
382+
mSatPerAsset: mSatPerAsset,
380383
}
381384
}
382385

@@ -388,11 +391,8 @@ func (m *MockPriceOracle) QueryAskPrice(_ context.Context,
388391
// Calculate the rate expiryDelay lifetime.
389392
expiry := uint64(time.Now().Unix()) + m.expiryDelay
390393

391-
mSatPerUsd := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) /
392-
lnwire.MilliSatoshi(m.usdPerBTC)
393-
394394
return &OracleAskResponse{
395-
AskPrice: &mSatPerUsd,
395+
AskPrice: &m.mSatPerAsset,
396396
Expiry: expiry,
397397
}, nil
398398
}
@@ -404,11 +404,8 @@ func (m *MockPriceOracle) QueryBidPrice(_ context.Context, _ *asset.ID,
404404
// Calculate the rate expiryDelay lifetime.
405405
expiry := uint64(time.Now().Unix()) + m.expiryDelay
406406

407-
mSatPerUsd := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) /
408-
lnwire.MilliSatoshi(m.usdPerBTC)
409-
410407
return &OracleBidResponse{
411-
BidPrice: &mSatPerUsd,
408+
BidPrice: &m.mSatPerAsset,
412409
Expiry: expiry,
413410
}, nil
414411
}

0 commit comments

Comments
 (0)