-
Notifications
You must be signed in to change notification settings - Fork 2
/
context.go
36 lines (31 loc) · 1.06 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package newop
import "github.com/muun/libwallet/operation"
// PaymentContext stores data required to analyze and validate an operation
type PaymentContext struct {
FeeWindow *FeeWindow
NextTransactionSize *NextTransactionSize
ExchangeRateWindow *ExchangeRateWindow
PrimaryCurrency string
MinFeeRateInSatsPerVByte float64
SubmarineSwap *SubmarineSwap
}
func (c *PaymentContext) totalBalance() int64 {
return c.NextTransactionSize.toInternalType().TotalBalance()
}
func (c *PaymentContext) toBitcoinAmount(sats int64, inputCurrency string) *BitcoinAmount {
amount := c.ExchangeRateWindow.convert(
NewMonetaryAmountFromSatoshis(sats),
inputCurrency,
)
return &BitcoinAmount{
InSat: sats,
InInputCurrency: amount,
InPrimaryCurrency: c.ExchangeRateWindow.convert(amount, c.PrimaryCurrency),
}
}
func newPaymentAnalyzer(context *PaymentContext) *operation.PaymentAnalyzer {
return operation.NewPaymentAnalyzer(
context.FeeWindow.toInternalType(),
context.NextTransactionSize.toInternalType(),
)
}