-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction.go
65 lines (54 loc) · 1.75 KB
/
transaction.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package txtax
type Transaction struct {
TimeStamp int64 `json:"timeStamp"`
Hash string `json:"hash"`
Amount float32 `json:"amount"`
MarketValue float32 `json:"marketValue"`
Type TransactionType `json:"type"`
Category TxCategory `json:"category"`
Currency Currency `json:"currency"`
IsDisabled bool `json:"isActive"`
Gas float32 `json:"gas"` // amount of fee in $ that was used for transaction
}
type TransactionType string
var (
TransactionTypeGift TransactionType = "GIFT"
TransactionTypeDonation TransactionType = "DONATION"
TransactionTypeStolen TransactionType = "STOLEN"
TransactionTypeAirdrop TransactionType = "AIRDROP"
TransactionTypeFork TransactionType = "FORK"
TransactionTypePayment TransactionType = "PAYMENT"
TransactionTypeReward TransactionType = "REWARD"
)
type TxCategory string
var (
TxCategoryDeposit TxCategory = "DEPOSIT"
TxCategoryWithdraw TxCategory = "WITHDRAW"
)
type TaxMethod string
var (
TaxMethodFIFO TaxMethod = "FIFO"
TaxMethodLIFO TaxMethod = "LIFO"
TaxMethodHIFO TaxMethod = "HIFO"
)
type Currency string
type TaxOptions struct {
TaxMethod TaxMethod
IncomeTypes map[TransactionType]struct{} // taxable events: deposits only
CGLTypes map[TransactionType]struct{} // taxable events: withdraws only
SkipTypes map[TransactionType]struct{} // don't do anything
}
func (t *Transaction) Total() float32 {
return t.Amount*t.MarketValue - t.Gas
}
func GetHIFOTransactionIDx(transactions []Transaction) int {
highest := &transactions[0]
idx := 0
for i, value := range transactions {
if highest.MarketValue < value.MarketValue && value.Amount > 0 {
highest = &value
idx = i
}
}
return idx
}