chaincode

package
v0.0.0-...-db48615 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Proposed  = "proposed"
	Approved  = "approved"
	Committed = "committed"
)

Status for Proposal

View Source
const (
	ALL      = "all"
	MAJORITY = "majority"
)

Criteria for moving the next task

View Source
const (
	NewProposalEvent         = "newProposalEvent"
	DeleteProposalEvent      = "deleteProposalEvent"
	NewVoteEvent             = "newVoteEvent"
	ReadyToUpdateConfigEvent = "readyToUpdateConfigEvent"
	UpdateConfigEvent        = "updateConfigEvent"
)

Chaincode event names

View Source
const (
	UpdateAction   = "update"
	CreationAction = "create"
)

Action types for channel operation

View Source
const (
	SystemChannelType      = "system"
	OpsChannelType         = "ops"
	ApplicationChannelType = "application"
	DisableChannelType     = "disable"
)

Channel types

View Source
const (
	ChannelObjectType = "channel"
)

Object types

View Source
const (
	NetworkUpdateEvent = "networkUpdateEvent"
)

ChaincodeEvents

View Source
const (
	ProposalObjectType = "proposal"
)

Object types

Variables

View Source
var (
	// ErrProposalNotFound is returned when the requested object is not found.
	ErrProposalNotFound = fmt.Errorf("proposal not found")
	// ErrProposalIDAreadyInUse is returned when the requested proposal ID is already in use.
	ErrProposalIDAreadyInUse = fmt.Errorf("proposalID already in use")
	// ErrInconsistentChannelID is returned when the channel ID is inconsistent with the ID in the artifacts.
	ErrInconsistentChannelID = fmt.Errorf("channel ID is inconsistent with the ID in the artifacts")
)

Functions

This section is empty.

Types

type Artifacts

type Artifacts struct {
	// ConfigUpdate contains the base64 string representation of the common.ConfigUpdate
	ConfigUpdate string `json:"configUpdate"`

	// Signatures contains a map of signatures: mspID -> base64 string representation of common.ConfigSignature
	Signatures map[string]string `json:"signatures,omitempty" metadata:",optional"`
}

Artifacts contains artifacts for a channel update proposal

type Channel

type Channel struct {
	ObjectType    string            `json:"docType"`       //docType is used to distinguish the various types of objects in state database
	ID            string            `json:"ID"`            // Channel ID
	ChannelType   string            `json:"channelType"`   // Channel Type
	Organizations map[string]string `json:"organizations"` // Set of MSP IDs
}

Channel describes channel information which includes the channel ID and organizations participating in the channel.

type EventDetail

type EventDetail struct {
	ProposalID       string   `json:"proposalID"`
	OperationTargets []string `json:"operationTargets"`
}

EventDetail represents details of chaincode events which is issued in the chaincode.

type Proposal

type Proposal struct {
	//docType is used to distinguish the various types of objects in state database
	ObjectType string `json:"docType"`

	// ID is the ID of the proposal
	ID string `json:"ID"`

	// ChannelID is the channel ID targeted by the proposal
	ChannelID string `json:"channelID"`

	// Description describes the proposal
	Description string `json:"description,omitempty" metadata:",optional"`

	// Creator describes the msp ID of the proposal creator
	Creator string `json:"creator"`

	// Action describes the action type of the proposed update ('update' or 'create')
	Action string `json:"action"`

	// Status is the status of the proposal
	Status string `json:"status"`

	// OpsProfile is the ops profile used for the input of configtx-cli to create the ConfigUpdate.
	// This is the information corresponding to Artifacts.ConfigUpdate.
	OpsProfile interface{} `json:"opsProfile"`

	// Artifacts contains the artifacts for the channel update proposal
	Artifacts Artifacts `json:"artifacts"`
}

Proposal gathers all information of a proposed update, including all added signatures.

type ProposalInput

type ProposalInput struct {
	ID           string      `json:"ID"`
	ChannelID    string      `json:"channelID"`
	Description  string      `json:"description,omitempty" metadata:",optional"`
	Action       string      `json:"action,omitempty" metadata:",optional"`
	OpsProfile   interface{} `json:"opsProfile"`
	ConfigUpdate string      `json:"configUpdate"`
	Signature    string      `json:"signature"`
}

ProposalInput represents a request input of a new proposal.

type SmartContract

type SmartContract struct {
	contractapi.Contract
}

SmartContract provides functions for operating channels

func (*SmartContract) AddOrganization

func (s *SmartContract) AddOrganization(ctx contractapi.TransactionContextInterface, channelID string, mspID string) error

AddOrganization upserts an organization's MSP ID as a member of the given channel.

Arguments:

0: channelID - the target channel ID
1: mspID - the MSP ID of newly added or updated member

Returns:

0: error

func (*SmartContract) ChannelExists

func (s *SmartContract) ChannelExists(ctx contractapi.TransactionContextInterface, channelID string) (bool, error)

ChannelExists returns true when the channel with the given ID exists in the ledger.

Arguments:

0: channelID - the target channel ID

Returns:

0: whether that the channel with the given ID exists or not
1: error

func (*SmartContract) CountOrganizationsInChannel

func (s *SmartContract) CountOrganizationsInChannel(ctx contractapi.TransactionContextInterface, channelID string) (int, error)

CountOrganizationsInChannel returns the number of organizations participating in the given channel.

Arguments:

0: channelID - the target channel ID

Returns:

0: the number of organizations participating in the given channel
1: error

func (*SmartContract) CreateChannel

func (s *SmartContract) CreateChannel(ctx contractapi.TransactionContextInterface, channelID string, channelType string, mspIDs []string) error

CreateChannel issues a new channel information.

Arguments:

0: channelID - the channel ID to be recorded
1: channelType - the type of the channel (if this is empty, "application" is set as the default value)
2: mspIDs - the list of members of the channel

Returns:

0: error

func (*SmartContract) GetAllChannels

func (s *SmartContract) GetAllChannels(ctx contractapi.TransactionContextInterface) ([]*Channel, error)

GetAllChannels returns the all channel information stored in the ledger.

Arguments: none

Returns:

0: the list of the all channel information
1: error

func (*SmartContract) GetAllProposals

GetAllProposals returns the all channel update proposals.

Arguments: none

Returns:

0: the map of the all channel update proposals
1: error

func (*SmartContract) GetChannelType

func (s *SmartContract) GetChannelType(ctx contractapi.TransactionContextInterface, channelID string) (string, error)

GetChannelType returns the channel type of the given channel

Arguments:

0: channelID - the target channel ID

Returns:

0: the channel type
1: error

func (*SmartContract) GetOrganizationsInChannel

func (s *SmartContract) GetOrganizationsInChannel(ctx contractapi.TransactionContextInterface, channelID string) ([]string, error)

GetOrganizationsInChannel returns the list of organizations participating in the given channel.

Arguments:

0: channelID - the target channel ID

Returns:

0: the list of organizations participating in given channel
1: error

func (*SmartContract) GetProposal

func (s *SmartContract) GetProposal(ctx contractapi.TransactionContextInterface, proposalID string) (*Proposal, error)

GetProposal returns the proposal with the given ID.

Arguments:

0: params - the ID of the proposal

Returns:

0: the proposal with the given ID
1: error

func (*SmartContract) GetSystemChannelID

func (s *SmartContract) GetSystemChannelID(ctx contractapi.TransactionContextInterface) (string, error)

GetSystemChannelID returns the system channel ID stored in the ledger

Arguments: none

Returns:

0: the system channel ID
1: error

func (*SmartContract) NotifyCommitResult

func (s *SmartContract) NotifyCommitResult(ctx contractapi.TransactionContextInterface, proposalID string) error

NotifyCommitResult records the result of the commit for the channel update proposal. This function records the vote as a state into the ledger. Also, this changes the status of the proposal from approved to committed. If the status is changed, this updates channel info in the states in the ledger based on the committed channel update.

Arguments:

0: proposalID - the ID for voting for the channel update proposal
1: signature - the base64 string representation of common.ConfigSignature for signing by the creator to the ConfigUpdate

Returns:

0: error

Events:

(if the channel info is updated)
name: UpdateConfigEvent(<proposalID>)
payload: proposalID

func (*SmartContract) ReadChannel

func (s *SmartContract) ReadChannel(ctx contractapi.TransactionContextInterface, channelID string) (*Channel, error)

ReadChannel returns the channel information stored in the ledger with the given channel ID.

Arguments:

0: channelID - the target channel ID

Returns:

0: the channel with the given ID
1: error

func (*SmartContract) RequestProposal

RequestProposal requests a new channel update proposal.

Arguments:

0: input - the request input for the channel update proposal

Returns:

0: the created proposal ID
1: error

Events:

name: newProposalEvent(<proposalID>)
payload: the created proposal ID

func (*SmartContract) SetOrganizations

func (s *SmartContract) SetOrganizations(ctx contractapi.TransactionContextInterface, channelID string, mspIDs []string) error

SetOrganizations replaces the members of the given channel with the given MSP ID list.

Arguments:

0: channelID - the target channel ID
1: mspIDs - the MSP ID list

Returns:

0: error

func (*SmartContract) UpdateChannelType

func (s *SmartContract) UpdateChannelType(ctx contractapi.TransactionContextInterface, channelID string, channelType string) error

UpdateChannelType replaces the type of the given channel.

Arguments:

0: channelID - the target channel ID
1: channelType - the type of the channel

Returns:

0: error

func (*SmartContract) Vote

func (s *SmartContract) Vote(ctx contractapi.TransactionContextInterface, proposalID, signature string) error

Vote votes for the channel update proposal. This function records the vote as a state into the ledger. Also, if the proposal is voted by MAJORITY, this changes the status of the proposal from proposed to approved.

Arguments:

0: proposalID - the ID for voting for the channel update proposal
1: signature - the base64 string representation of common.ConfigSignature for signing by the creator to the ConfigUpdate

Returns:

0: error

Events:

(if the status is changed to approved)
name: ReadyToUpdateConfigEvent(<proposalID>)
payload: EventDetail
(else)
name: NewVoteEvent(<proposalID>)
payload: proposalID

Directories

Path Synopsis
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