This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
model_sync_config.go
48 lines (40 loc) · 1.74 KB
/
model_sync_config.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
package bux
import (
"bytes"
"database/sql/driver"
"encoding/json"
"github.com/BuxOrg/bux/utils"
)
// SyncConfig is the configuration used for syncing a transaction (on-chain)
type SyncConfig struct {
Broadcast bool `json:"broadcast" toml:"broadcast" yaml:"broadcast"` // Transaction should be broadcasted
BroadcastInstant bool `json:"broadcast_instant" toml:"broadcast_instant" yaml:"broadcast_instant"` // Transaction should be broadcasted instantly (ASAP)
PaymailP2P bool `json:"paymail_p2p" toml:"paymail_p2p" yaml:"paymail_p2p"` // Transaction will be sent to all related paymail providers if P2P is detected
SyncOnChain bool `json:"sync_on_chain" toml:"sync_on_chain" yaml:"sync_on_chain"` // Transaction should be checked that it's on-chain
// FUTURE IDEAS:
// DelayToBroadcast time.Duration `json:"delay_to_broadcast" toml:"delay_to_broadcast" yaml:"delay_to_broadcast"` // Delay for broadcasting
// Miner string `json:"miner" toml:"miner" yaml:"miner"` // Use a specific miner
// miners: []miner{name, token, feeQuote}
// default: miner
// failover: miner
// keep tx updated until x blocks?
}
// Scan will scan the value into Struct, implements sql.Scanner interface
func (t *SyncConfig) Scan(value interface{}) error {
if value == nil {
return nil
}
byteValue, err := utils.ToByteArray(value)
if err != nil || bytes.Equal(byteValue, []byte("")) || bytes.Equal(byteValue, []byte("\"\"")) {
return nil
}
return json.Unmarshal(byteValue, &t)
}
// Value return json value, implement driver.Valuer interface
func (t SyncConfig) Value() (driver.Value, error) {
marshal, err := json.Marshal(t)
if err != nil {
return nil, err
}
return string(marshal), nil
}