Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthorizingSigners ¶ added in v0.51.0
func AuthorizingSigners(tb *flow.TransactionBody) []flow.Address
AuthorizingSigners returns the deduplicated addresses whose signatures authorize the transaction's actions: the proposer followed by the authorizers (in insertion order). If the same account appears in multiple roles, only its first occurrence is included. Empty addresses (e.g. an unset proposer on the system transaction) are omitted.
The payer is deliberately excluded: its signature only authorizes paying the transaction's fees, not the transaction's actions.
A nil transaction body returns nil, allowing callers holding an optional *TransactionBody (e.g. a non-transaction procedure such as a script) to call this function without a nil check.
Types ¶
type AccountChange ¶
type Inspector ¶
type Inspector interface {
// Inspect
// - storage is the execution state before the procedure was executed.
// only the executionSnapshot.Reads, will be read
// - executionSnapshot is the reads and writes of the procedure
// - events are all of the events the procedure is emitting
// - signers are the transaction's authorizing signers, as returned by
// [AuthorizingSigners]. Empty for procedures that are not transactions
// (e.g. scripts).
Inspect(
logger zerolog.Logger,
storage snapshot.StorageSnapshot,
executionSnapshot *snapshot.ExecutionSnapshot,
events []flow.Event,
signers []flow.Address,
) (Result, error)
// Name is the name of the inspector
Name() string
}
Inspector is run after each procedure on the procedure output and the starting state of a procedure It will then fill out the ProcedureOutput.Inspection results
type Result ¶
type Result interface {
InspectionName() string
AsLogEvent() (zerolog.Level, func(e *zerolog.Event))
}
Result is the result of a procedure inspector
type SearchToken ¶
type SearchToken struct {
ID string
GetBalance func(value *interpreter.CompositeValue) uint64
// TODO: optimize by using decoded events
SinksSources map[string]SourceSink
}
type SignerAllowlistViolation ¶ added in v0.51.0
type SignerAllowlistViolation struct {
// TokenID is the token whose supply changed.
TokenID string
// EventType is the event type ID that triggered the violation.
EventType string
// Amount is the signed token-amount delta decoded from the event.
Amount int64
// Signers are the transaction's authorizing signers.
Signers []flow.Address
}
SignerAllowlistViolation records a source/sink event (e.g. a mint or burn) observed in a transaction whose authorizing signers did not include any account from the event's configured SignerAllowlist.
type SourceSink ¶ added in v0.51.0
type SourceSink struct {
// Amount decodes the signed token-amount delta from the event. A positive
// value is a source (tokens entering/created); a negative value is a sink
// (tokens leaving/destroyed).
Amount func(flow.Event) (int64, error)
// SignerAllowlist, when non-nil, restricts which accounts may trigger this
// event. The check passes if at least one of the transaction's authorizing
// signers (see [AuthorizingSigners]) is in the set. A nil map disables the
// check (the default, preserving prior behavior).
SignerAllowlist map[flow.Address]struct{}
}
SourceSink describes how to account for a single event type that changes a token's supply (a source/mint with a positive amount, or a sink/burn with a negative amount), and optionally restricts which accounts may trigger it.
type TokenChanges ¶
type TokenChanges struct {
// contains filtered or unexported fields
}
func NewTokenChangesInspector ¶
func NewTokenChangesInspector(searchedTokens TokenChangesSearchTokens, chain flow.ChainID) *TokenChanges
NewTokenChangesInspector return a TokenChanges inspector, that will be run after transaction execution and analyze if any unaccounted tokens were created or destroyed.
func (*TokenChanges) Inspect ¶
func (td *TokenChanges) Inspect( log zerolog.Logger, storage snapshot.StorageSnapshot, executionSnapshot *snapshot.ExecutionSnapshot, events []flow.Event, signers []flow.Address, ) (diff Result, err error)
Inspect gets the token diff from a state diff - thread safe - not deterministic (iterates over maps)! So it should not be used to affect execution! - will not panic - might return an error, but it is safe to ignore since this for information/reporting
Inspect could technically be run on chunk data packs.
func (*TokenChanges) Name ¶
func (td *TokenChanges) Name() string
func (*TokenChanges) SetSearchedTokens ¶
func (td *TokenChanges) SetSearchedTokens(searchedTokens TokenChangesSearchTokens)
SetSearchedTokens are safe to replace whenever. The change will not affect the inspections already in progress. TODO: this can be tied into the admin commands
type TokenChangesSearchTokens ¶
type TokenChangesSearchTokens map[string]SearchToken
func DefaultTokenDiffSearchTokens ¶
func DefaultTokenDiffSearchTokens(chain flow.Chain) TokenChangesSearchTokens
DefaultTokenDiffSearchTokens returns the default settings for token inspection
type TokenDiffResult ¶
type TokenDiffResult struct {
// Changes in token balances per account
// parsed from the state changes
Changes map[flow.Address]AccountChange
// KnownSourcesSinks is a map (by token id) of
// know mints/burns for the token parsed from predetermined events
KnownSourcesSinks map[string]int64
// authorizing signers included no allow-listed account. Empty when no
// allow-list is configured or all matched events were authorized.
UnauthorizedSourcesSinks []SignerAllowlistViolation
}
TokenDiffResult is the result of the inspection
func (TokenDiffResult) AsLogEvent ¶
func (r TokenDiffResult) AsLogEvent() (zerolog.Level, func(e *zerolog.Event))
func (TokenDiffResult) InspectionName ¶
func (r TokenDiffResult) InspectionName() string
func (TokenDiffResult) UnaccountedTokens ¶
func (r TokenDiffResult) UnaccountedTokens() map[string]int64