-
Notifications
You must be signed in to change notification settings - Fork 82
/
transaction.go
83 lines (67 loc) · 2.62 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2018 Shift Devices AG
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package accounts
import (
"time"
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/coin"
)
// TxType is a type of transaction. See the TxType* constants.
type TxType string
const (
// TxTypeReceive is a tx which sends funds to our account.
TxTypeReceive TxType = "receive"
// TxTypeSend is a tx which sends funds out of our account.
TxTypeSend TxType = "send"
// TxTypeSendSelf is a tx from out account to our account.
TxTypeSendSelf TxType = "sendSelf"
)
// TxStatus is the the status of the tx and helps the frontend show the appropriate information.
type TxStatus string
const (
// TxStatusPending means the tx is unconfirmed.
TxStatusPending TxStatus = "pending"
// TxStatusComplete means the tx is complete, depending on the number of confirmations needed
// for the respective coin.
TxStatusComplete TxStatus = "complete"
// TxStatusFailed means the tx is confirmed but considered failed, e.g. a ETH transaction which
TxStatusFailed TxStatus = "failed"
)
// AddressAndAmount holds an address and the corresponding amount.
type AddressAndAmount struct {
Address string
// Amount is the amount sent to or received on the address in a transaction.
Amount coin.Amount
// Ours is true if the address is one of our receive addresses.
Ours bool
}
// Transaction models a transaction with common transaction info.
type Transaction interface {
// Fee is nil for a receiving tx. The fee is only displayed (and relevant) when sending funds
// from the wallet.
Fee() *coin.Amount
// Time of confirmation. nil for unconfirmed tx or when the headers are not synced yet.
Timestamp() *time.Time
// ID is the tx ID.
ID() string
// NumConfirmations is the number of confirmations. 0 for unconfirmed.
NumConfirmations() int
// Status is the tx status. See TxStatus docs for details.
Status() TxStatus
// Type returns the type of the transaction.
Type() TxType
// Amount is always >0 and is the amount received or sent (not including the fee).
Amount() coin.Amount
// Addresses money was sent to / received on.
Addresses() []AddressAndAmount
}