authcointx

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 11 Imported by: 9

README

Auth Coin Transfer Extension

The auth coin transfer extension provides the ability to ensure only authorized addresses can receive/send coins. Only the condition authorized to do so is able to define which addresses are authorized and which aren't. The condition that defines who is authorized to do so can also only changed by the one(s) owning the current condition authorized to do this and the address authorization.

⚠ This extension also overwrites the standard Rivine 0x01 transaction controller, and disabled 0x00 transactions by allowing it to be decoded but not validated.

⚠ This extensions adds a rule that is applied to all transaction versions. Using this extensions means that coin inputs and coin outputs can only be sent if: all parties are authorized, or if only one address is involved with just a single refund coin output.

An initial condition is passed to the extensions which will be used as the authorized condition until it is changed.

It is recommended to use a multisignature condition as the authorized mint condition.

                                                     +
                                                     +
                                                                          (B) Coin Transfer
                                                     +                 +----------------------+
                                                     +                 |                      |
                                                                       | +--+                 |
                                                  +-----+              | +-----------+        |
                     (C) Deauthorize              |     |   Block      | | Wallet    |        |
                   +---------------------+     +->+     |   N+2        | | for       |        |
              +----+   AddressA          +-----+  +--+--+              | | Address A |        |
+---------+   |    +---------------------+           |                 | +-----+-----+        |
|Authority+---+                                   +--+--+  +-----------+       |              |
+---+-----+                                       |     +<-+           |       |  Transfer    |
    |                                             |     |   Block      |       |  X Coins     |
    |                                             +--+--+   N+1        | +--+  v              |
    |                                                |                 | +-----+-----+        |
    |                (A) Authorize                +--+--+              | | Wallet    |        |
    |               +--------------------+        |     |   Block      | | for       |        |
    +---------------+ AddressA, AddressB +------->+     |   N          | | Address B |        |
                    +--------------------+        +--+--+              | +-----------+        |
                                                     |                 |                      |
                                                     +                 +----------------------+

                                                     +
                                                     +
  • An address is by default not authorized;
  • Only addresses that are authorized (A) by the authority can send or receive tokens;
    • Two addresses can transfer tokens between one another (B) as both the sender and receiver are authorized;
    • This implies that tokens linked to an unauthorized address are locked until it is authorized again;
  • Addresses that are authorized can be deauthorized again (C) (locking any funds still on the address);

Transactions

Auth Address Update Transactions

These transactions are used to authorize and deauthorize addresses. Only addresses that are authorized at the transactions' blockheight can receive (coin outputs targetting the authorized address) or send (coin inputs coming from the authorized address) coins.

JSON Encoding an Auth Address Update Transaction
{
	// 0xB0, an example version number of an  Auth Address Update Transaction
	"version": 176, // the decimal representation of the above example version number
	// Auth Address Update Transaction Data
	"data": {
		// crypto-random 8-byte array (base64-encoded to a string) to ensure
		// the uniqueness of this transaction's ID
		"nonce": "FoAiO8vN2eU=",
		// it is not required to define auth addresses,
		// but an Auth Address Update transaction requires at least one auth address
		// or one deauth address to be defined
		"authaddresses": [
			"0112210f9efa5441ab705226b0628679ed190eb4588b662991747ea3809d93932c7b41cbe4b732",
			"01450aeb140c58012cb4afb48e068f976272fefa44ffe0991a8a4350a3687558d66c8fc753c37e",
		],
		"deauthaddresses": [
			"019e9b6f2d43a44046b62836ce8d75c935ff66cbba1e624b3e9755b98ac176a08dac5267b2c8ee",
		],
		// arbitrary data, can contain anything as long as it
		// fits within 83 bytes, and is optional
		"arbitrarydata": "dGVzdC4uLiAxLCAyLi4uIDM="
		// fulfillment which fulfills the AuthCondition,
		// can be any type of fulfillment as long as it is
		// valid AND fulfills the AuthCondition
		"authfulfillment": {
			"type": 1,
			"data": {
				"publickey": "ed25519:d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d7780",
				"signature": "bdf023fbe7e0efec584d254b111655e1c2f81b9488943c3a712b91d9ad3a140cb0949a8868c5f72e08ccded337b79479114bdb4ed05f94dfddb359e1a6124602"
			}
		},
	}
}

See the [Rivine documentation about JSON-encoding of v1 Transactions][rivine-tx-v1] for more information about the primitive data types used, as well as the meaning and encoding of the different types of unlock conditions and fulfillments.

Binary Encoding an Auth Address Update Transaction

The binary encoding of an Auth Address UpdateTransaction uses the Rivine encoding package. In order to understand the binary encoding of such a transaction, please see [the Rivine encoding documentation][rivine-encoding] and Rivine binary encoding of a v1 transaction in order to understand how an Auth Address Update Transaction is binary encoded. That documentation also contains an in-detail documented example of a binary encoding v1 transaction.

The same transaction that was shown as an example of a JSON-encoded Auth Address Update Transaction, can be represented in a hexadecimal string —when binary encoded— as:

b01680223bcbcdd9e5040112210f9efa5441ab705226b0628679ed190eb4588b662991747ea3809d93932c01450aeb140c58012cb4afb48e068f976272fefa44ffe0991a8a4350a3687558d602019e9b6f2d43a44046b62836ce8d75c935ff66cbba1e624b3e9755b98ac176a08d22746573742e2e2e20312c20322e2e2e203301c401d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d778080bdf023fbe7e0efec584d254b111655e1c2f81b9488943c3a712b91d9ad3a140cb0949a8868c5f72e08ccded337b79479114bdb4ed05f94dfddb359e1a6124602
Signing an Auth Address Update Transaction

It is assumed that the reader of this chapter has already read [Rivine's Introduction to Signing Transactions][rivine-signing-into] and all its referenced content.

In order to sign this type of transaction, you first need to compute the hash, which is used as message, which we'll than to create a signature using the Ed25519 algorithm.

Computing that hash can be represented by following pseudo code:

blake2b_256_hash(SiaBinaryEncoding(
  - transactionVersion: 1 byte
  - specifier: 16 bytes, hardcoded to "auth addr update"
  - nonce: 8 bytes
  - slice of auth addresses
  - slice of deauth addresses
  - arbitraryData: 8 bytes length + n bytes
)) : 32 bytes fixed-size crypto hash
Auth Condition Update Transactions

These transactions are used to change the condition authorized to use these transactions

An Auth condition can be any of the following conditions:

  • (1) An [UnlockHash Condition][rivine-condition-uh]: it is a single person (or multiple people owning the same private key for the same wallet);
  • (2) A [MultiSignature Condition][rivine-condition-multisig]: it is a multi signature wallet, most likely meaning multiple people owning different private keys that all have a certain degree of control in the same multi signature wallet, allowing them to come to a consensus on the creation of coins and redefinition of who the coin creators are (to be);
  • (3) An [TimeLocked Condition][rivine-condition-tl]: the minting powers (creation of coins and redefinition of the coin creators) are locked until a certain (unix epoch) timestamp or block height. Once this height or time is reached, the internal condition (an [UnlockHash Condition][rivine-condition-uh] (1) or a [MultiSignature Condition][rivine-condition-multisig]) (2) is the condition that defines who can create coins and redefine who the coin creators are to be. Prior to this timestamp or block height no-one can create coins or redefine who the coin creators are to be, not even the ones defined by the internal condition of the currently active [TimeLocked Condition][rivine-condition-tl]. as well as to authorize and deauthorize addresses that can (no longer) send/receive tokens.

The Genesis Auth Condition is hardcoded.

In practice a MultiSignature Condition will always be used as AuthCondition, this is however not a consensus-defined requirement, as discussed earlier.

JSON Encoding an Auth Condition Update Transaction
{
	// 0xB1, an example version number of an Auth Condition Update Transaction
	"version": 177, // the decimal representation of the above example version number
	// Auth Condition Update Transaction Data
	"data": {
		// crypto-random 8-byte array (base64-encoded to a string) to ensure
		// the uniqueness of this transaction's ID
		"nonce": "1oQFzIwsLs8=",
		// arbitrary data, can contain anything as long as it
		// fits within 83 bytes, and is optional.
		"arbitrarydata": "dGVzdC4uLiAxLCAyLi4uIDM="
		// condition which will become the new AuthCondition
		// once the transaction is part of a created block and
		// until there is a newer block with another accepted AuthCondition
		"authcondition": {
			"type": 1,
			"data": {
				"unlockhash": "01e78fd5af261e49643dba489b29566db53fa6e195fa0e6aad4430d4f06ce88b73e047fe6a0703"
			}
		},
		// fulfillment which fulfills the current active AuthCondition,
		// can be any type of fulfillment as long as it is
		// valid AND fulfills the current active AuthCondition
		"authfulfillment": {
			"type": 1,
			"data": {
				"publickey": "ed25519:d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d7780",
				"signature": "ad59389329ed01c5ee14ce25ae38634c2b3ef694a2bdfa714f73b175f979ba6613025f9123d68c0f11e8f0a7114833c0aab4c8596d4c31671ec8a73923f02305"
			}
		},
	}
}

See the [Rivine documentation about JSON-encoding of v1 Transactions][rivine-tx-v1] for more information about the primitive data types used, as well as the meaning and encoding of the different types of unlock conditions and fulfillments.

Binary Encoding an Auth Condition Update Transaction

The binary encoding of an Auth Condition Update Transaction uses the Rivine encoding package. In order to understand the binary encoding of such a transaction, please see [the Rivine encoding documentation][rivine-encoding] and Rivine binary encoding of a v1 transaction in order to understand how an Auth Condition Update Transaction binary encoded. That documentation also contains an in-detail documented example of a binary encoding v1 transaction.

The same transaction that was shown as an example of a JSON-encoded Auth Condition Update Transaction, can be represented in a hexadecimal string —when binary encoded— as:

b1d68405cc8c2c2ecf22746573742e2e2e20312c20322e2e2e2033014201e78fd5af261e49643dba489b29566db53fa6e195fa0e6aad4430d4f06ce88b7301c401d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d778080ad59389329ed01c5ee14ce25ae38634c2b3ef694a2bdfa714f73b175f979ba6613025f9123d68c0f11e8f0a7114833c0aab4c8596d4c31671ec8a73923f02305
Signing an Auth Condition Update Transaction

It is assumed that the reader of this chapter has already read [Rivine's Introduction to Signing Transactions][rivine-signing-into] and all its referenced content.

In order to sign an auth condition update transaction, you first need to compute the hash, which is used as message, which we'll than to create a signature using the Ed25519 algorithm.

Computing that hash can be represented by following pseudo code:

blake2b_256_hash(SiaBinaryEncoding(
  - transactionVersion: 1 byte
  - specifier: 16 bytes, hardcoded to "auth cond update"
  - nonce: 8 bytes
  - auth condition
  - arbitraryData: 8 bytes length + n bytes
)) : 32 bytes fixed-size crypto hash

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SpecifierAuthAddressUpdateTransaction   = types.Specifier{'a', 'u', 't', 'h', ' ', 'a', 'd', 'd', 'r', ' ', 'u', 'p', 'd', 'a', 't', 'e'}
	SpecifierAuthConditionUpdateTransaction = types.Specifier{'a', 'u', 't', 'h', ' ', 'c', 'o', 'n', 'd', ' ', 'u', 'p', 'd', 'a', 't', 'e'}
)

These Specifiers are used internally when calculating a Transaction's ID. See Rivine's Specifier for more details.

Functions

func DefaultUnauthorizedCoinTransactionExceptionCallback

func DefaultUnauthorizedCoinTransactionExceptionCallback(tx modules.ConsensusTransaction, dedupAddresses []types.UnlockHash, ctx types.TransactionValidationContext) (bool, error)

DefaultUnauthorizedCoinTransactionExceptionCallback is the default callback that is used in ase the auth coin plugin does not define a custom callback.

Types

type AuthAddressBaseTransactionController added in v1.3.1

type AuthAddressBaseTransactionController struct {
	RequireMinerFees bool
}

AuthAddressBaseTransactionController is the base controller for all authaddress controllers, that require miner fees.

type AuthAddressUpdateTransaction

type AuthAddressUpdateTransaction struct {
	// Nonce used to ensure the uniqueness of a AuthAddressUpdateTransaction's ID and signature.
	Nonce types.TransactionNonce `json:"nonce"`
	// AuthAddresses contains a list of addresses to be authorized,
	// it is also considered valid to authorize an address that is already authorized.
	AuthAddresses []types.UnlockHash `json:"authaddresses"`
	// AuthAddresses contains a list of addresses to be authorized,
	// it is also considered valid to deauthorize an address that has no authorization.
	DeauthAddresses []types.UnlockHash `json:"deauthaddresses"`
	// ArbitraryData can be used for any purpose
	ArbitraryData []byte `json:"arbitrarydata,omitempty"`
	// AuthFulfillment defines the fulfillment which is used in order to
	// fulfill the globally defined AuthCondition.
	AuthFulfillment types.UnlockFulfillmentProxy `json:"authfulfillment"`
	// Minerfees, a fee paid for this minter definition transaction.
	MinerFees []types.Currency `json:"minerfees,omitempty"`
}

AuthAddressUpdateTransaction is to be used by the owner(s) of the Authorized Condition, as a medium in order to (de)authorize address(es).

/!\ This transaction requires NO Miner Fee.

func AuthAddressUpdateTransactionFromTransaction

func AuthAddressUpdateTransactionFromTransaction(tx types.Transaction, expectedVersion types.TransactionVersion, requireMinerFees bool) (AuthAddressUpdateTransaction, error)

AuthAddressUpdateTransactionFromTransaction creates a AuthAddressUpdateTransaction, using a regular in-memory rivine transaction.

Past the (tx) Version validation it piggy-backs onto the `AuthAddressUpdateTransactionFromTransactionData` constructor.

func AuthAddressUpdateTransactionFromTransactionData

func AuthAddressUpdateTransactionFromTransactionData(txData types.TransactionData, requireMinerFees bool) (AuthAddressUpdateTransaction, error)

AuthAddressUpdateTransactionFromTransactionData creates a AuthAddressUpdateTransaction, using the TransactionData from a regular in-memory rivine transaction.

func (*AuthAddressUpdateTransaction) Transaction

Transaction returns this AuthAddressUpdateTransaction as regular rivine transaction, using AuthAddressUpdateTransaction as the type.

func (*AuthAddressUpdateTransaction) TransactionData

func (autx *AuthAddressUpdateTransaction) TransactionData() types.TransactionData

TransactionData returns this AuthAddressUpdateTransaction as regular rivine transaction data.

type AuthAddressUpdateTransactionController

type AuthAddressUpdateTransactionController struct {
	AuthAddressBaseTransactionController

	// AuthInfoGetter is used to get (coin) authorization information.
	AuthInfoGetter AuthInfoGetter

	// TransactionVersion is used to validate/set the transaction version
	// of an auth address update transaction.
	TransactionVersion types.TransactionVersion
}

AuthAddressUpdateTransactionController defines a custom transaction controller, for an Auth AddressUpdate Transaction. It allows the modification of the set of addresses that are authorizes in order to receive or send coins.

func (AuthAddressUpdateTransactionController) DecodeTransactionData

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (AuthAddressUpdateTransactionController) EncodeTransactionData

func (autc AuthAddressUpdateTransactionController) EncodeTransactionData(w io.Writer, txData types.TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (AuthAddressUpdateTransactionController) EncodeTransactionIDInput

func (autc AuthAddressUpdateTransactionController) EncodeTransactionIDInput(w io.Writer, txData types.TransactionData) error

EncodeTransactionIDInput implements TransactionIDEncoder.EncodeTransactionIDInput

func (AuthAddressUpdateTransactionController) GetCommonExtensionData

func (autc AuthAddressUpdateTransactionController) GetCommonExtensionData(extension interface{}) (types.CommonTransactionExtensionData, error)

GetCommonExtensionData implements TransactionCommonExtensionDataGetter.GetCommonExtensionData

func (AuthAddressUpdateTransactionController) JSONDecodeTransactionData

func (autc AuthAddressUpdateTransactionController) JSONDecodeTransactionData(data []byte) (types.TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (AuthAddressUpdateTransactionController) JSONEncodeTransactionData

func (autc AuthAddressUpdateTransactionController) JSONEncodeTransactionData(txData types.TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

func (AuthAddressUpdateTransactionController) SignExtension

func (autc AuthAddressUpdateTransactionController) SignExtension(extension interface{}, sign func(*types.UnlockFulfillmentProxy, types.UnlockConditionProxy, ...interface{}) error) (interface{}, error)

SignExtension implements TransactionExtensionSigner.SignExtension

func (AuthAddressUpdateTransactionController) SignatureHash

func (autc AuthAddressUpdateTransactionController) SignatureHash(t types.Transaction, extraObjects ...interface{}) (crypto.Hash, error)

SignatureHash implements TransactionSignatureHasher.SignatureHash

type AuthAddressUpdateTransactionExtension

type AuthAddressUpdateTransactionExtension struct {
	Nonce           types.TransactionNonce
	AuthAddresses   []types.UnlockHash
	DeauthAddresses []types.UnlockHash
	AuthFulfillment types.UnlockFulfillmentProxy
}

AuthAddressUpdateTransactionExtension defines the AuthAddressUpdateTransaction Extension Data

type AuthConditionUpdateTransaction

type AuthConditionUpdateTransaction struct {
	// Nonce used to ensure the uniqueness of a AuthConditionUpdateTransaction's ID and signature.
	Nonce types.TransactionNonce `json:"nonce"`
	// ArbitraryData can be used for any purpose
	ArbitraryData []byte `json:"arbitrarydata,omitempty"`
	// AuthCondition defines the condition which will have to fulfilled
	// in order to prove powers of authority when changing power (again) or using those powers to update
	// the set of authorized addresses.
	AuthCondition types.UnlockConditionProxy `json:"authcondition"`
	// AuthFulfillment defines the fulfillment which is used in order to
	// fulfill the globally defined AuthCondition.
	AuthFulfillment types.UnlockFulfillmentProxy `json:"authfulfillment"`
	// Minerfees, a fee paid for this minter definition transaction.
	MinerFees []types.Currency `json:"minerfees,omitempty"`
}

AuthConditionUpdateTransaction is to be used by the owner(s) of the Authorized Condition, as a medium in order transfer the authorization power to a new condition.

/!\ This transaction requires NO Miner Fee.

func AuthConditionUpdateTransactionFromTransaction

func AuthConditionUpdateTransactionFromTransaction(tx types.Transaction, expectedVersion types.TransactionVersion, requireMinerFees bool) (AuthConditionUpdateTransaction, error)

AuthConditionUpdateTransactionFromTransaction creates a AuthConditionUpdateTransaction, using a regular in-memory rivine transaction.

Past the (tx) Version validation it piggy-backs onto the `AuthAddressUpdateTransactionFromTransactionData` constructor.

func AuthConditionUpdateTransactionFromTransactionData

func AuthConditionUpdateTransactionFromTransactionData(txData types.TransactionData, requireMinerFees bool) (AuthConditionUpdateTransaction, error)

AuthConditionUpdateTransactionFromTransactionData creates a AuthConditionUpdateTransaction, using the TransactionData from a regular in-memory rivine transaction.

func (*AuthConditionUpdateTransaction) Transaction

Transaction returns this AuthAddressUpdateTransaction as regular rivine transaction, using AuthAddressUpdateTransaction as the type.

func (*AuthConditionUpdateTransaction) TransactionData

func (autx *AuthConditionUpdateTransaction) TransactionData() types.TransactionData

TransactionData returns this AuthAddressUpdateTransaction as regular rivine transaction data.

type AuthConditionUpdateTransactionController

type AuthConditionUpdateTransactionController struct {
	AuthAddressBaseTransactionController

	// AuthInfoGetter is used to get (coin) authorization information.
	AuthInfoGetter AuthInfoGetter

	// TransactionVersion is used to validate/set the transaction version
	// of an auth address update transaction.
	TransactionVersion types.TransactionVersion
}

AuthConditionUpdateTransactionController defines a custom transaction controller, for an Auth ConditionUpdate Transaction. It allows the modification of the set of addresses that are authorizes in order to receive or send coins.

func (AuthConditionUpdateTransactionController) DecodeTransactionData

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (AuthConditionUpdateTransactionController) EncodeTransactionData

func (cutc AuthConditionUpdateTransactionController) EncodeTransactionData(w io.Writer, txData types.TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (AuthConditionUpdateTransactionController) EncodeTransactionIDInput

func (cutc AuthConditionUpdateTransactionController) EncodeTransactionIDInput(w io.Writer, txData types.TransactionData) error

EncodeTransactionIDInput implements TransactionIDEncoder.EncodeTransactionIDInput

func (AuthConditionUpdateTransactionController) GetCommonExtensionData

func (cutc AuthConditionUpdateTransactionController) GetCommonExtensionData(extension interface{}) (types.CommonTransactionExtensionData, error)

GetCommonExtensionData implements TransactionCommonExtensionDataGetter.GetCommonExtensionData

func (AuthConditionUpdateTransactionController) JSONDecodeTransactionData

func (cutc AuthConditionUpdateTransactionController) JSONDecodeTransactionData(data []byte) (types.TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (AuthConditionUpdateTransactionController) JSONEncodeTransactionData

func (cutc AuthConditionUpdateTransactionController) JSONEncodeTransactionData(txData types.TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

func (AuthConditionUpdateTransactionController) SignExtension

func (cutc AuthConditionUpdateTransactionController) SignExtension(extension interface{}, sign func(*types.UnlockFulfillmentProxy, types.UnlockConditionProxy, ...interface{}) error) (interface{}, error)

SignExtension implements TransactionExtensionSigner.SignExtension

func (AuthConditionUpdateTransactionController) SignatureHash

func (cutc AuthConditionUpdateTransactionController) SignatureHash(t types.Transaction, extraObjects ...interface{}) (crypto.Hash, error)

SignatureHash implements TransactionSignatureHasher.SignatureHash

type AuthConditionUpdateTransactionExtension

type AuthConditionUpdateTransactionExtension struct {
	Nonce           types.TransactionNonce
	AuthCondition   types.UnlockConditionProxy
	AuthFulfillment types.UnlockFulfillmentProxy
}

AuthConditionUpdateTransactionExtension defines the AuthConditionUpdateTransaction Extension Data

type AuthInfoGetter

type AuthInfoGetter interface {
	// GetActiveAuthCondition returns the active auth condition.
	// In other words, the auth condition at the current block height.
	GetActiveAuthCondition() (types.UnlockConditionProxy, error)
	// GetAuthConditionAt returns the auth condition at a given block height.
	GetAuthConditionAt(height types.BlockHeight) (types.UnlockConditionProxy, error)

	// GetAddressesAuthStateNow rerturns for each requested address, in order as given,
	// the current auth state for that address as a boolean: true if authed, false otherwise.
	// If exitEarlyFn is given GetAddressesAuthStateNow can stop earlier in case exitEarlyFn returns true for an iteration.
	GetAddressesAuthStateNow(addresses []types.UnlockHash, exitEarlyFn func(index int, state bool) bool) ([]bool, error)

	// GetAddressesAuthStateAt rerturns for each requested address, in order as given,
	// the auth state at the given height for that address as a boolean: true if authed, false otherwise.
	// If exitEarlyFn is given GetAddressesAuthStateNow can stop earlier in case exitEarlyFn returns true for an iteration.
	GetAddressesAuthStateAt(height types.BlockHeight, addresses []types.UnlockHash, exitEarlyFn func(index int, state bool) bool) ([]bool, error)
}

AuthInfoGetter allows you to check if a list of addresses are authorized, as well as what the auth condition is at a given (as well as current) [block] height.

type Plugin

type Plugin struct {
	RequireMinerFees bool
	// contains filtered or unexported fields
}

Plugin is a struct defines the Auth. Coin Transfer plugin

func NewPlugin

func NewPlugin(genesisAuthCondition types.UnlockConditionProxy, authAddressUpdateTransactionVersion, authConditionUpdateTransactionVersion types.TransactionVersion, opts *PluginOpts) *Plugin

NewPlugin creates a new Plugin with a genesisAuthCondition and correct transaction versions. NOTE: do not register the default rivine transaction versions (0x00 and 0x01) if you use this plugin!!!

func (*Plugin) ApplyBlock

func (p *Plugin) ApplyBlock(block modules.ConsensusBlock, bucket *persist.LazyBoltBucket) error

ApplyBlock applies a block's minting transactions to the minting bucket.

func (*Plugin) ApplyBlockHeader added in v1.3.1

ApplyBlockHeader applies nothing and has no effect on this plugin.

func (*Plugin) ApplyTransaction

func (p *Plugin) ApplyTransaction(txn modules.ConsensusTransaction, bucket *persist.LazyBoltBucket) error

ApplyTransaction applies a minting transactions to the minting bucket.

func (*Plugin) Close

func (p *Plugin) Close() error

Close unregisters the plugin from the consensus

func (*Plugin) GetActiveAuthCondition

func (p *Plugin) GetActiveAuthCondition() (types.UnlockConditionProxy, error)

GetActiveAuthCondition implements types.AuthInfoGetter.GetActiveAuthCondition

func (*Plugin) GetAddressesAuthStateAt

func (p *Plugin) GetAddressesAuthStateAt(height types.BlockHeight, addresses []types.UnlockHash, exitEarlyFn func(index int, state bool) bool) ([]bool, error)

GetAddressesAuthStateAt rerturns for each requested address, in order as given, the auth state at the given height for that address as a boolean: true if authed, false otherwise. If exitEarlyFn is given GetAddressesAuthStateNow can stop earlier in case exitEarlyFn returns true for an iteration.

func (*Plugin) GetAddressesAuthStateNow

func (p *Plugin) GetAddressesAuthStateNow(addresses []types.UnlockHash, exitEarlyFn func(index int, state bool) bool) ([]bool, error)

GetAddressesAuthStateNow rerturns for each requested address, in order as given, the current auth state for that address as a boolean: true if authed, false otherwise. If exitEarlyFn is given GetAddressesAuthStateNow can stop earlier in case exitEarlyFn returns true for an iteration.

func (*Plugin) GetAuthConditionAt

func (p *Plugin) GetAuthConditionAt(height types.BlockHeight) (types.UnlockConditionProxy, error)

GetAuthConditionAt implements types.AuthInfoGetter.GetAuthConditionAt

func (*Plugin) InitPlugin

func (p *Plugin) InitPlugin(metadata *persist.Metadata, bucket *bolt.Bucket, storage modules.PluginViewStorage, unregisterCallback modules.PluginUnregisterCallback) (persist.Metadata, error)

InitPlugin initializes the Bucket for the first time

func (*Plugin) RevertBlock

func (p *Plugin) RevertBlock(block modules.ConsensusBlock, bucket *persist.LazyBoltBucket) error

RevertBlock reverts a block's minting transaction from the minting bucket

func (*Plugin) RevertBlockHeader added in v1.3.1

RevertBlockHeader reverts nothing and has no effect on this plugin.

func (*Plugin) RevertTransaction

func (p *Plugin) RevertTransaction(txn modules.ConsensusTransaction, bucket *persist.LazyBoltBucket) error

RevertTransaction reverts a minting transaction from the minting bucket

func (*Plugin) TransactionValidatorVersionFunctionMapping

func (p *Plugin) TransactionValidatorVersionFunctionMapping() map[types.TransactionVersion][]modules.PluginTransactionValidationFunction

TransactionValidatorVersionFunctionMapping returns all tx validators for specific tx versions linked to this plugin

func (*Plugin) TransactionValidators

func (p *Plugin) TransactionValidators() []modules.PluginTransactionValidationFunction

TransactionValidators returns all tx validators linked to this plugin

type PluginOpts

type PluginOpts struct {
	// UnauthorizedCoinTransactionExceptionCallback is a callback that can be defined,
	// in case your chain requires custom logic to define what transaction can be considered valid for
	// coin transfers with unauthorized addresses due to whatever rules (e.g. version, pure refund coin flow, ...)
	UnauthorizedCoinTransactionExceptionCallback UnauthorizedCoinTransactionExceptionCallback

	// UnlockHashFilter can be used to filter what unlock hashes require authorization and which not.
	// It is optional, and if none given, all unlockhashes except
	// the NilUnlockHash and AtomicSwap contract addresses require authorization.
	// Returns true in case authorization cheque is required, False otherwise.
	UnlockHashFilter func(types.UnlockHash) bool
	// RequireMinerFees can be used to enable minerfees on authorization transactions.
	RequireMinerFees bool
	// Reverse can be used to reverse the logic of this plugin.
	// This means that by default all addresses are authorized and can send transactions.
	Reverse bool
}

PluginOpts are extra optional configurations one can make to the AuthCoin Plugin

type UnauthorizedCoinTransactionExceptionCallback

type UnauthorizedCoinTransactionExceptionCallback func(tx modules.ConsensusTransaction, dedupAddresses []types.UnlockHash, ctx types.TransactionValidationContext) (bool, error)

UnauthorizedCoinTransactionExceptionCallback is the function signature for the callback that can be used for chains that requires custom logic to define what transaction can be considered valid for coin transfers with unauthorized addresses due to whatever rules (e.g. version, pure refund coin flow, ...) True is returned in case this tx does not require an authorization check, False otherwise.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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