network

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Valid   = driver.Valid   // Valid indicates the transaction is valid and committed.
	Invalid = driver.Invalid // Invalid indicates the transaction is invalid and has been discarded.
	Busy    = driver.Busy    // Busy indicates the transaction is still being processed.
	Unknown = driver.Unknown // Unknown indicates the transaction state is not known.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	// contains filtered or unexported fields
}

Envelope wraps a ledger-specific transaction envelope.

func (*Envelope) Bytes

func (e *Envelope) Bytes() ([]byte, error)

Bytes serializes the envelope into bytes.

func (*Envelope) FromBytes

func (e *Envelope) FromBytes(raw []byte) error

FromBytes deserializes an envelope from bytes.

func (*Envelope) MarshalJSON

func (e *Envelope) MarshalJSON() ([]byte, error)

MarshalJSON provides custom JSON marshaling for the envelope.

func (*Envelope) String

func (e *Envelope) String() string

String returns a string representation of the envelope.

func (*Envelope) TxID

func (e *Envelope) TxID() string

TxID returns the transaction identifier within the envelope.

func (*Envelope) UnmarshalJSON

func (e *Envelope) UnmarshalJSON(raw []byte) error

UnmarshalJSON provides custom JSON unmarshaling for the envelope.

type FinalityListener

type FinalityListener interface {
	// OnStatus is called when the status of a transaction changes.
	OnStatus(ctx context.Context, txID string, status int, message string, tokenRequestHash []byte)
	// OnError is called when the finality event cannot be delivered after all retries are exhausted
	OnError(ctx context.Context, txID string, err error)
}

FinalityListener defines the interface for receiving notifications when a transaction's status changes on the ledger.

type GetFunc

type GetFunc func() (view.Identity, []byte, error)

GetFunc is a function type that returns identity and raw byte information.

type Ledger

type Ledger struct {
	// contains filtered or unexported fields
}

Ledger provides high-level access to the distributed ledger for status checks and state queries.

func (*Ledger) GetStates

func (l *Ledger) GetStates(ctx context.Context, namespace string, keys ...string) ([][]byte, error)

GetStates returns the raw byte values for the given keys in a specific namespace.

func (*Ledger) Status

func (l *Ledger) Status(id string) (ValidationCode, string, error)

Status returns the validation code for a specific transaction ID.

func (*Ledger) TransferMetadataKey

func (l *Ledger) TransferMetadataKey(k string) (string, error)

TransferMetadataKey returns the ledger key associated with transfer metadata for a given key.

type LocalMembership

type LocalMembership struct {
	// contains filtered or unexported fields
}

LocalMembership provides access to identities managed by the local node.

func NewLocalMembership

func NewLocalMembership(lm driver.LocalMembership) *LocalMembership

NewLocalMembership creates a new LocalMembership wrapper.

func (*LocalMembership) AnonymousIdentity

func (l *LocalMembership) AnonymousIdentity() (view.Identity, error)

AnonymousIdentity returns a fresh anonymous identity for privacy-preserving operations.

func (*LocalMembership) DefaultIdentity

func (l *LocalMembership) DefaultIdentity() view.Identity

DefaultIdentity returns the default identity of the local node.

type Network

type Network struct {
	// contains filtered or unexported fields
}

Network serves as the primary bridge to a specific blockchain network (e.g., Fabric or FabricX). it provides methods for broadcasting transactions, requesting approvals, and monitoring finality.

func GetInstance

func GetInstance(sp token.ServiceProvider, network, channel string) *Network

GetInstance returns a network instance for the given network and channel

func NewNetwork

func NewNetwork(n driver.Network, localMembership *LocalMembership) *Network

NewNetwork creates a new Network instance.

func (*Network) AddFinalityListener

func (n *Network) AddFinalityListener(namespace string, txID string, listener FinalityListener) error

AddFinalityListener registers a listener to be notified when a transaction reaches a final state on the ledger.

func (*Network) AnonymousIdentity

func (n *Network) AnonymousIdentity() (view.Identity, error)

AnonymousIdentity returns a fresh anonymous identity from the local membership.

func (*Network) AreTokensSpent

func (n *Network) AreTokensSpent(ctx context.Context, namespace string, tokenIDs []*token2.ID, meta []string) ([]bool, error)

AreTokensSpent checks the spent status of multiple tokens on the ledger.

func (*Network) Broadcast

func (n *Network) Broadcast(ctx context.Context, blob any) error

Broadcast submits a transaction envelope or generic blob to the network's ordering service.

func (*Network) Channel

func (n *Network) Channel() string

Channel returns the name of the channel or partition within the network.

func (*Network) ComputeTxID

func (n *Network) ComputeTxID(id *TxID) string

ComputeTxID calculates the transaction identifier in the network's native format.

func (*Network) Connect

func (n *Network) Connect(ns string) ([]token.ServiceOption, error)

Connect establishes a connection to the network for a specific namespace.

func (*Network) FetchPublicParameters

func (n *Network) FetchPublicParameters(namespace string) ([]byte, error)

FetchPublicParameters retrieves the public parameters for a specific namespace from the network.

func (*Network) GetTransactionStatus

func (n *Network) GetTransactionStatus(ctx context.Context, namespace, txID string) (status int, tokenRequestHash []byte, message string, err error)

GetTransactionStatus retrieves the current status and token request hash for a transaction.

func (*Network) Ledger

func (n *Network) Ledger() (*Ledger, error)

Ledger provides access to the ledger service for this network.

func (*Network) LocalMembership

func (n *Network) LocalMembership() *LocalMembership

LocalMembership returns the local membership service associated with this network.

func (*Network) LookupTransferMetadataKey

func (n *Network) LookupTransferMetadataKey(namespace, key string, timeout time.Duration, opts ...token.ServiceOption) ([]byte, error)

LookupTransferMetadataKey performs a ledger scan to find a metadata key matching the provided sub-key.

func (*Network) Name

func (n *Network) Name() string

Name returns the identifier of the network.

func (*Network) NewEnvelope

func (n *Network) NewEnvelope() *Envelope

NewEnvelope creates a new, empty ledger-specific transaction envelope.

func (*Network) Normalize

func (n *Network) Normalize(opt *token.ServiceOptions) (*token.ServiceOptions, error)

Normalize fills in default values for network, channel, and namespace in the service options.

func (*Network) QueryTokens

func (n *Network) QueryTokens(ctx context.Context, namespace string, IDs []*token2.ID) ([][]byte, error)

QueryTokens retrieves the raw byte representation of tokens from the ledger.

func (*Network) RequestApproval

func (n *Network) RequestApproval(context view.Context, tms *token.ManagementService, requestRaw []byte, signer view.Identity, txID TxID, metadata driver.TransientMap) (*Envelope, error)

RequestApproval sends a token request to an endorsement service and returns the resulting endorsed envelope. metadata carries optional application-level key-value pairs forwarded to the approver backend.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider manages multiple Network instances, providing lazy initialization and lookup by network/channel ID.

func GetProvider

func GetProvider(sp token.ServiceProvider) *Provider

GetProvider retrieves the network Provider from the service provider.

func NewProvider

func NewProvider(configService *ftsconfig.Service) *Provider

NewProvider returns a new network Provider instance.

func (*Provider) Connect

func (p *Provider) Connect() error

Connect initializes and connects all configured token management systems to their respective networks.

func (*Provider) GetNetwork

func (p *Provider) GetNetwork(network string, channel string) (*Network, error)

GetNetwork returns the Network instance for the specified network and channel identifiers.

func (*Provider) Normalize

func (p *Provider) Normalize(opt *token.ServiceOptions) (*token.ServiceOptions, error)

Normalize ensures that network-related options are fully populated based on the configured environment.

func (*Provider) RegisterDriver

func (p *Provider) RegisterDriver(driver driver.Driver)

RegisterDriver adds a new network driver to the provider.

type TransientMap

type TransientMap map[string][]byte

TransientMap models the transient data passed with a transaction proposal, which is not persisted on the ledger.

func (TransientMap) Exists

func (m TransientMap) Exists(key string) bool

Exists checks if a specific key is present in the transient map.

func (TransientMap) Get

func (m TransientMap) Get(id string) []byte

Get retrieves a raw byte slice from the transient map.

func (TransientMap) GetState

func (m TransientMap) GetState(key string, state any) error

GetState unmarshals a JSON-encoded value from the transient map into a Go object.

func (TransientMap) IsEmpty

func (m TransientMap) IsEmpty() bool

IsEmpty returns true if the transient map has no entries.

func (TransientMap) Set

func (m TransientMap) Set(key string, raw []byte) error

Set adds a raw byte slice to the transient map.

func (TransientMap) SetState

func (m TransientMap) SetState(key string, state any) error

SetState marshals a Go object into JSON and stores it in the transient map.

type TxID

type TxID struct {
	// Nonce is a random byte slice used to ensure uniqueness.
	Nonce []byte
	// Creator is the serialized identity of the transaction creator.
	Creator []byte
}

TxID represents a unique transaction identifier composed of a nonce and the creator's identity.

func (*TxID) String

func (t *TxID) String() string

String returns a string representation of the transaction ID.

type ValidationCode

type ValidationCode = driver.ValidationCode

ValidationCode represents the status of a transaction on the ledger.

Directories

Path Synopsis
rws/translator/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
endorsement/fsc/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
tcc
tcc/main command
tcc/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
finality/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
finality/queue/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
lookup/mock
Code generated by counterfeiter.
Code generated by counterfeiter.
pp
qe
tms
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL