-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdecoder.go
More file actions
79 lines (65 loc) · 2.63 KB
/
decoder.go
File metadata and controls
79 lines (65 loc) · 2.63 KB
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
package decoder
import (
"context"
"fmt"
"github.com/smartcontractkit/mcms"
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/types"
experimentalanalyzer "github.com/smartcontractkit/chainlink-deployments-framework/experimental/analyzer"
)
// ProposalDecoder decodes MCMS proposals into structured DecodedTimelockProposal
type ProposalDecoder interface {
Decode(ctx context.Context, env deployment.Environment, proposal *mcms.TimelockProposal) (types.DecodedTimelockProposal, error)
}
// legacyDecoder adapts the legacy experimental/analyzer package to the new decoder interface
type legacyDecoder struct {
evmABIMappings map[string]string
solanaDecoders map[string]experimentalanalyzer.DecodeInstructionFn
}
// NewLegacyDecoder creates a decoder that wraps legacy experimental/analyzer decoding logic.
// Use functional options to configure:
// - WithEVMABIMappings: override proposal context EVM ABI mappings
// - WithSolanaDecoders: override proposal context Solana decoder mappings
func NewLegacyDecoder(opts ...DecoderOption) ProposalDecoder {
decoder := &legacyDecoder{}
for _, opt := range opts {
opt(decoder)
}
return decoder
}
// DecoderOption is a functional option for configuring the decoder
type DecoderOption func(*legacyDecoder)
// WithEVMABIMappings overrides the proposal context EVM ABI mappings used during decoding.
func WithEVMABIMappings(mappings map[string]string) DecoderOption {
return func(d *legacyDecoder) {
d.evmABIMappings = mappings
}
}
// WithSolanaDecoders overrides the proposal context Solana decoder mappings used during decoding.
func WithSolanaDecoders(decoders map[string]experimentalanalyzer.DecodeInstructionFn) DecoderOption {
return func(d *legacyDecoder) {
d.solanaDecoders = decoders
}
}
func (d *legacyDecoder) Decode(
ctx context.Context,
env deployment.Environment,
proposal *mcms.TimelockProposal,
) (types.DecodedTimelockProposal, error) {
proposalCtx, err := experimentalanalyzer.NewDefaultProposalContext(env,
experimentalanalyzer.WithEVMABIMappings(d.evmABIMappings),
experimentalanalyzer.WithSolanaDecoders(d.solanaDecoders),
)
if err != nil {
return nil, fmt.Errorf("failed to create proposal context: %w", err)
}
// Build the report using legacy experimental analyzer
report, err := experimentalanalyzer.BuildTimelockReport(ctx, proposalCtx, env, proposal)
if err != nil {
return nil, fmt.Errorf("failed to build timelock report: %w", err)
}
// Convert to our DecodedTimelockProposal interface
return &decodedTimelockProposal{
report: report,
}, nil
}