-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.go
67 lines (58 loc) · 1.95 KB
/
writer.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
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
package platdot
import (
"github.com/rjman-self/platdot-utils/core"
metrics "github.com/rjman-self/platdot-utils/metrics/types"
"github.com/rjman-self/platdot-utils/msg"
"github.com/ChainSafe/log15"
"github.com/rjman-self/Platdot/bindings/Bridge"
)
var _ core.Writer = &writer{}
var PassedStatus uint8 = 2
var TransferredStatus uint8 = 3
var CancelledStatus uint8 = 4
type writer struct {
cfg Config
conn Connection
bridgeContract *Bridge.Bridge // instance of bound receiver bridgeContract
log log15.Logger
stop <-chan int
sysErr chan<- error // Reports fatal error to core
metrics *metrics.ChainMetrics
}
// NewWriter creates and returns writer
func NewWriter(conn Connection, cfg *Config, log log15.Logger, stop <-chan int, sysErr chan<- error, m *metrics.ChainMetrics) *writer {
return &writer{
cfg: *cfg,
conn: conn,
log: log,
stop: stop,
sysErr: sysErr,
metrics: m,
}
}
func (w *writer) start() error {
w.log.Debug("Starting Alaya writer...")
return nil
}
// setContract adds the bound receiver bridgeContract to the writer
func (w *writer) setContract(bridge *Bridge.Bridge) {
w.bridgeContract = bridge
}
// ResolveMessage handles any given message based on type
// A bool is returned to indicate failure/success, this should be ignored except for within tests.
func (w *writer) ResolveMessage(m msg.Message) bool {
w.log.Info("Attempting to resolve message", "type", m.Type, "src", m.Source, "dst", m.Destination, "nonce", m.DepositNonce, "rId", m.ResourceId.Hex(), "recipient", m.Payload[1])
switch m.Type {
case msg.FungibleTransfer:
return w.createErc20Proposal(m)
case msg.NonFungibleTransfer:
return w.createErc721Proposal(m)
case msg.GenericTransfer:
return w.createGenericDepositProposal(m)
default:
w.log.Error("Unknown message type received", "type", m.Type)
return false
}
}