minting

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: 13 Imported by: 12

README

Rivine minting extension

The minting extensions provides the ability to mint tokens without any prior backing (see: create coins). Only the condition authorized to do so is able to mint new tokens or change the condition that's authorized to do this from then on.

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.

Usage

Daemon

After creating the consensus module and registering the HTTP handlers you can use following snippet:

// This is an unlockcondition for testing purposes.
uhString := "01fbaa166912244082784a28ec8756d5d2126f789ed25d93074b2afa05f984e32c0ae996e398e5"
var uh types.UnlockHash
if err := uh.LoadString(uhString); err != nil {
    panic(err)
}
condition := types.NewUnlockHashCondition(uh)

/* any condition that is defined types.unlockconditions.go can be passed to NewMintingPlugin
    for example this can be one of following:
    * singlesignature condition, which is an unlockhash
    * timelock condition
    * multisignature condition
*/

// define the transaction versions for the 2 extra transactions possible
const (
	// can be any unique transaction version >= 128
	minterDefinitionTxVersion = iota + 128
	coinCreationTxVersion
	coinDestructionTxVersion
)

// Pass the condition the NewMintingPlugin
plugin := minting.NewMintingPlugin(types.NewCondition(condition), minterDefinitionTxVersion, coinCreationTxVersion, &minting.MintingPluginOptions{
	CoinDestructionTransactionVersion: coinDestructionTxVersion, // if equals 0 -> disabled
	UseLegacySiaEncoding: false, // false by default, usng rivine encoding, otherwise it uses sia encoding if true
	RequireMinerFees: false, // false by default, otherwise it adds and requires miner fees if true
})

err = cs.RegisterPlugin(context.BackGround(),"minting", plugin)
if err != nil {
	plugin.Close() // Close it since it can still hold resources
    return err
}

This will register the minting plugin on the consensus.

Client

After creating the command line client you can use following snippet

import (
    mintingcli "github.com/threefoldtech/rivine/extensions/minting/client"
)

// Will create the explore mintcondition command
// * rivinec explore mintcondition [height] [flags]
err := mintingcli.CreateExploreCmd(cliClient)
if err != nil {
	panic(err)
}

// define the transaction versions for the 2 extra transactions possible
const (
	// can be any unique transaction version >= 128
	minterDefinitionTxVersion = iota + 128
	coinCreationTxVersion
	coinDestructionTxVersion
)

// Will create the createCoinTransaction and createMinterDefinitionTransaction command
// * rivinec wallet create minterdefinitiontransaction
// * rivinec wallet create coincreationtransaction
mintingcli.CreateWalletCmds(cliClient, minterDefinitionTxVersion, coinCreationTxVersion, &mintingcli.WalletCmdsOpts{
	CoinDestructionTxVersion: coinDestructionTxVersion, // tx version of the coin destruction tx
	RequireMinerFees: false, // false by default, otherwise it adds and requires miner fees if true
})

mintingReader := mintingcli.NewPluginExplorerClient(cliClient)

// Register the transaction types
types.RegisterTransactionVersion(minterDefinitionTxVersion, minting.MinterDefinitionTransactionController{
	MintConditionGetter: mintingReader,
	TransactionVersion: minterDefinitionTxVersion,
})
types.RegisterTransactionVersion(coinCreationTxVersion, minting.CoinCreationTransactionController{
	MintConditionGetter: mintingReader,
	TransactionVersion: coinCreationTxVersion,
})
types.RegisterTransactionVersion(coinDestructionTxVersion, minting.CoinDestructionTransactionController{
	MintConditionGetter: mintingReader,
	TransactionVersion: coinDestructionTxVersion,
})

Transactions

Minter Definition Transactions

Minter Definition Transactions are used to redefine the creators of coins (AKA minters). These transactions can only be created by the Coin Creators. The (previously-defined) mint condition —meaning the mint condition active at the height of the (to be) created Minter Definition Transaction— defines who the coin creators are and thus who can redefine who the coin creators are to become. A mint 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].

The Coin Creation transactions defines 4 fields:

  • mintfulfillment: the fulfillment which has to fulfill the consensus-defined MintCondition, just the same as that a Coin Input's fulfillment has to fulfill the condition of the Coin Output it is about to spend;
  • mintcondition: the condition which will become the new mint condition (that has to be fulfilled in order to create coins and redefine the mint condition, in other words the condition that defines who the coin creators are) once the transaction is part of a created block and until there is a newer block with an accepted mint condition;
  • minerfees: defines the transaction fee(s) (works the same as in regular transactions);
  • arbitrarydata: describes the reason for creating these coins;
  • nonce: a crypto-random 8-byte array, used to ensure the uniqueness of this transaction's ID;

The Genesis Mint Condition is hardcoded.

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

JSON Encoding a Minter Definition Transaction
{
	// 0x80, an example version number of a Minter Definition Transaction
	"version": 128, // the decimal representation of the above example version number
	// Coin Creation Transaction Data
	"data": {
		// crypto-random 8-byte array (base64-encoded to a string) to ensure
		// the uniqueness of this transaction's ID
		"nonce": "FoAiO8vN2eU=",
		// fulfillment which fulfills the MintCondition,
		// can be any type of fulfillment as long as it is
		// valid AND fulfills the MintCondition
		"mintfulfillment": {
			"type": 1,
			"data": {
				"publickey": "ed25519:d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d7780",
				"signature": "bdf023fbe7e0efec584d254b111655e1c2f81b9488943c3a712b91d9ad3a140cb0949a8868c5f72e08ccded337b79479114bdb4ed05f94dfddb359e1a6124602"
			}
		},
		// condition which will become the new MintCondition
		// once the transaction is part of a created block and
		// until there is a newer block with another accepted MintCondition
		"mintcondition": {
			"type": 1,
			"data": {
				"unlockhash": "01e78fd5af261e49643dba489b29566db53fa6e195fa0e6aad4430d4f06ce88b73e047fe6a0703"
			}
		},
		// the transaction fees to be paid, also paid in
		// newly created) coins, rather than inputs
		"minerfees": ["1000000000"],
		// arbitrary data, can contain anything as long as it
		// fits within 83 bytes, but is in practice used
		// to link the capacity added/created
		// with as a consequence the creation of
		// these transaction and its coin outputs
		"arbitrarydata": "dGVzdC4uLiAxLCAyLi4uIDM="
	}
}

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 a Minter Definition Transaction

The binary encoding of a Minter Definition 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 a Minter Definition 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 Minter Definition Transaction, can be represented in a hexadecimal string —when binary encoded— as:

801680223bcbcdd9e5018000000000000000656432353531390000000000000000002000000000000000d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d77804000000000000000bdf023fbe7e0efec584d254b111655e1c2f81b9488943c3a712b91d9ad3a140cb0949a8868c5f72e08ccded337b79479114bdb4ed05f94dfddb359e1a612460201210000000000000001e78fd5af261e49643dba489b29566db53fa6e195fa0e6aad4430d4f06ce88b73010000000000000004000000000000003b9aca00180000000000000061206d696e74657220646566696e6974696f6e2074657374
Signing a Minter Definition 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 a v1 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(RivineBinaryEncoding(
  - transactionVersion: 1 byte
  - specifier: 16 bytes, hardcoded to "minter defin tx\0"
  - nonce: 8 bytes
  - binaryEncoding(mintCondition)
  - length(minerFees): int64 (8 bytes, little endian)
  for each minerFee:
    - fee: Currency (8 bytes length + n bytes, little endian encoded)
  - arbitraryData: 8 bytes length + n bytes
)) : 32 bytes fixed-size crypto hash
Coin Creation Transactions

Coin Creation Transactions are used for the creation of new coins. These transactions can only be created by the Coin Creators (also called minters). The Mint Condition defines who the coin creators are. If it is an [UnlockHash Condition][rivine-condition-uh] it is a single person, while it will be a [MultiSignature Condition][rivine-condition-multisig] in case there are multiple coin creators that have to come to a consensus.

The Coin Creation transactions defines 4 fields:

  • mintfulfillment: the fulfillment which has to fulfill the consensus-defined MintCondition, just the same as that a Coin Input's fulfillment has to fulfill the condition of the Coin Output it is about to spend;
  • coinoutputs: defines coin outputs, the destination of coins (works the same as in regular transactions);
  • minerfees: defines the transaction fee(s) (works the same as in regular transactions);
  • arbitrarydata: describes the capacity that is created/added, creating these coins as a result;
  • nonce: a crypto-random 8-byte array, used to ensure the uniqueness of this transaction's ID;

The Genesis Mint Condition is hardcoded.

In practice a MultiSignature Condition will always be used as MintCondition, this is however not a consensus-defined requirement. You can ready more about this in the chapter on Minter Definition Transactions.

JSON Encoding a Coin Creation Transaction
{
	// 0x81, an example version number of a Coin Creation Transaction
	"version": 129, // the decimal representation of the above example version number
	// Coin Creation Transaction Data
	"data": {
		// crypto-random 8-byte array (base64-encoded to a string) to ensure
		// the uniqueness of this transaction's ID
		"nonce": "1oQFzIwsLs8=",
		// fulfillment which fulfills the MintCondition,
		// can be any type of fulfillment as long as it is
		// valid AND fulfills the MintCondition
		"mintfulfillment": {
			"type": 1,
			"data": {
				"publickey": "ed25519:d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d7780",
				"signature": "ad59389329ed01c5ee14ce25ae38634c2b3ef694a2bdfa714f73b175f979ba6613025f9123d68c0f11e8f0a7114833c0aab4c8596d4c31671ec8a73923f02305"
			}
		},
		// defines the recipients (as conditions) who are to
		// receive the paired (newly created) coin values
		"coinoutputs": [{
			"value": "500000000000000",
			"condition": {
				"type": 1,
				"data": {
					"unlockhash": "01e3cbc41bd3cdfec9e01a6be46a35099ba0e1e1b793904fce6aa5a444496c6d815f5e3e981ccf"
				}
			}
		}],
		// the transaction fees to be paid, also paid in
		// newly created) coins, rather than inputs
		"minerfees": ["1000000000"],
		// arbitrary data, can contain anything as long as it
		// fits within 83 bytes, but is in practice used
		// to link the capacity added/created
		// with as a consequence the creation of
		// these transaction and its coin outputs
		"arbitrarydata": "dGVzdC4uLiAxLCAyLi4uIDM="
	}
}

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 a Coin Creation Transaction

The binary encoding of a Coin Creation 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 a Coin Creation 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 Coin Creation Transaction, can be represented in a hexadecimal string —when binary encoded— as:

8133a6432220334946018000000000000000656432353531390000000000000000002000000000000000d285f92d6d449d9abb27f4c6cf82713cec0696d62b8c123f1627e054dc6d77804000000000000000a074b976556d6ea2e4ae8d51fbbb5ec99099f11918201abfa31cf80d415c8d5bdfda5a32d9cc167067b6b798e80c6c1a45f6fd9e0f01ac09053e767b15d310050100000000000000070000000000000001c6bf5263400001210000000000000001e78fd5af261e49643dba489b29566db53fa6e195fa0e6aad4430d4f06ce88b73010000000000000004000000000000003b9aca0012000000000000006d6f6e65792066726f6d2074686520736b79
Signing a Coin Creation 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 a v1 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(RivineBinaryEncoding(
  - transactionVersion: 1 byte
  - specifier: 16 bytes, hardcoded to "coin mint tx\0\0\0\0"
  - nonce: 8 bytes
  - length(coinOutputs): int64 (8 bytes, little endian)
  for each coinOutput:
    - value: Currency (8 bytes length + n bytes, little endian encoded)
    - binaryEncoding(condition)
  - length(minerFees): int64 (8 bytes, little endian)
  for each minerFee:
    - fee: Currency (8 bytes length + n bytes, little endian encoded)
  - arbitraryData: 8 bytes length + n bytes
)) : 32 bytes fixed-size crypto hash
Coin Destruction Transactions

Coin Destruction Transactions are used for the destruction of existing coins.

The Coin Destruction transactions defines 4 fields:

  • coininputs: the fulfillment which has to fulfill the consensus-defined MintCondition, just the same as that a Coin Input's fulfillment has to fulfill the condition of the Coin Output it is about to spend;
  • refundcoinoutput: defines coin outputs, the destination of coins (works the same as in regular transactions);
  • minerfees: defines the transaction fee(s) (works the same as in regular transactions);
  • arbitrarydata: describes the capacity that is created/added, creating these coins as a result;
JSON Encoding a Coin Destruction Transaction
{
	// 0x82, an example version number of a Coin Destruction Transaction
	"version": 130, // the decimal representation of the above example version number
	// Coin Creation Transaction Data
	"data": {
		// defines the coin outputs to be burned
		"coininputs": [
			{
				"parentid": "1100000000000000000000000000000000000000000000000000000000000011",
				"fulfillment": {
					"type": 1,
					"data": {
						"publickey": "ed25519:def123def123def123def123def123def123def123def123def123def123def1",
						"signature": "ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef"
					}
				}
			}
		],
		// defines the optonal coin outputs
		"coinoutputs": [{
			"value": "500000000000000",
			"condition": {
				"type": 1,
				"data": {
					"unlockhash": "01e3cbc41bd3cdfec9e01a6be46a35099ba0e1e1b793904fce6aa5a444496c6d815f5e3e981ccf"
				}
			}
		}],
		// the transaction fees to be paid, small partion of coins that are not burned
		"minerfees": ["1000000000"],
		// arbitrary data, can contain anything as long as it
		// fits within 83 bytes
		"arbitrarydata": "dGVzdC4uLiAxLCAyLi4uIDM="
	}
}

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 a Coin Destruction Transaction

The binary encoding of a Coin Destruction 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 a Coin Destruction 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 Coin Destruction Transaction, can be represented in a hexadecimal string —when binary encoded— as:

8202110000000000000000000000000000000000000000000000000000000000001101c401def123def123def123def123def123def123def123def123def123def123def180ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef12345ef020e01c6bf52634000014201e3cbc41bd3cdfec9e01a6be46a35099ba0e1e1b793904fce6aa5a444496c6d8102083b9aca0022746573742e2e2e20312c20322e2e2e2033
Signing a Coin Destruction 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 a v1 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(RivineBinaryEncoding(
  - transactionVersion: 1 byte
  - specifier: 16 bytes, hardcoded to "coin destruct tx\0"
  - nonce: 8 bytes
  - all coin inputs
  - all coin outputs
  - length(minerFees): int64 (8 bytes, little endian)
  for each minerFee:
    - fee: Currency (8 bytes length + n bytes, little endian encoded)
  - arbitraryData: 8 bytes length + n bytes
)) : 32 bytes fixed-size crypto hash

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SpecifierMintDefinitionTransaction  = types.Specifier{'m', 'i', 'n', 't', 'e', 'r', ' ', 'd', 'e', 'f', 'i', 'n', ' ', 't', 'x'}
	SpecifierCoinCreationTransaction    = types.Specifier{'c', 'o', 'i', 'n', ' ', 'm', 'i', 'n', 't', ' ', 't', 'x'}
	SpecifierCoinDestructionTransaction = types.Specifier{'c', 'o', 'i', 'n', ' ', 'd', 'e', 's', 't', 'r', 'o', 'y', ' ', 't', 'x'}
)

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

Functions

This section is empty.

Types

type CoinCreationTransaction

type CoinCreationTransaction struct {
	// Nonce used to ensure the uniqueness of a CoinCreationTransaction's ID and signature.
	Nonce types.TransactionNonce `json:"nonce"`
	// MintFulfillment defines the fulfillment which is used in order to
	// fulfill the globally defined MintCondition.
	MintFulfillment types.UnlockFulfillmentProxy `json:"mintfulfillment"`
	// CoinOutputs defines the coin outputs,
	// which contain the freshly created coins, adding to the total pool of coins
	// available in the rivine network.
	CoinOutputs []types.CoinOutput `json:"coinoutputs"`
	// Minerfees, a fee paid for this coin creation transaction.
	MinerFees []types.Currency `json:"minerfees,omitempty"`
	// ArbitraryData can be used for any purpose,
	// but is mostly to be used in order to define the reason/origins
	// of the coin creation.
	ArbitraryData []byte `json:"arbitrarydata,omitempty"`
}

CoinCreationTransaction is to be created only by the defined Coin Minters, as a medium in order to create coins (coin outputs), without backing them (so without having to spend previously unspend coin outputs, see: coin inputs).

func CoinCreationTransactionFromTransaction

func CoinCreationTransactionFromTransaction(tx types.Transaction, expectedVersion types.TransactionVersion, requireMinerFees bool) (CoinCreationTransaction, error)

CoinCreationTransactionFromTransaction creates a CoinCreationTransaction, using a regular in-memory rivine transaction.

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

func CoinCreationTransactionFromTransactionData

func CoinCreationTransactionFromTransactionData(txData types.TransactionData, requireMinerFees bool) (CoinCreationTransaction, error)

CoinCreationTransactionFromTransactionData creates a CoinCreationTransaction, using the TransactionData from a regular in-memory rivine transaction.

func (*CoinCreationTransaction) Transaction

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

func (*CoinCreationTransaction) TransactionData

func (cctx *CoinCreationTransaction) TransactionData() types.TransactionData

TransactionData returns this CoinCreationTransaction as regular rivine transaction data.

type CoinCreationTransactionController

type CoinCreationTransactionController struct {
	MintingMinerFeeBaseTransactionController

	// MintConditionGetter is used to get a mint condition at the context-defined block height.
	//
	// The found MintCondition defines the condition that has to be fulfilled
	// in order to mint new coins into existence (in the form of non-backed coin outputs).
	MintConditionGetter MintConditionGetter

	// TransactionVersion is used to validate/set the transaction version
	// of a coin creation transaction.
	TransactionVersion types.TransactionVersion
}

CoinCreationTransactionController defines a rivine-specific transaction controller, for a CoinCreation Transaction. It allows for the creation of Coin Outputs, without requiring coin inputs, but can only be used by the defined Coin Minters.

func (CoinCreationTransactionController) DecodeTransactionData

func (cctc CoinCreationTransactionController) DecodeTransactionData(r io.Reader) (types.TransactionData, error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (CoinCreationTransactionController) EncodeTransactionData

func (cctc CoinCreationTransactionController) EncodeTransactionData(w io.Writer, txData types.TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (CoinCreationTransactionController) EncodeTransactionIDInput

func (cctc CoinCreationTransactionController) EncodeTransactionIDInput(w io.Writer, txData types.TransactionData) error

EncodeTransactionIDInput implements TransactionIDEncoder.EncodeTransactionIDInput

func (CoinCreationTransactionController) JSONDecodeTransactionData

func (cctc CoinCreationTransactionController) JSONDecodeTransactionData(data []byte) (types.TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (CoinCreationTransactionController) JSONEncodeTransactionData

func (cctc CoinCreationTransactionController) JSONEncodeTransactionData(txData types.TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

func (CoinCreationTransactionController) SignExtension

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

SignExtension implements TransactionExtensionSigner.SignExtension

func (CoinCreationTransactionController) SignatureHash

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

SignatureHash implements TransactionSignatureHasher.SignatureHash

type CoinCreationTransactionExtension

type CoinCreationTransactionExtension struct {
	Nonce           types.TransactionNonce
	MintFulfillment types.UnlockFulfillmentProxy
}

CoinCreationTransactionExtension defines the CoinCreationTx Extension Data

type CoinDestructionTransaction

type CoinDestructionTransaction struct {
	// CoinInputs defines the coin outputs that are being spent.
	CoinInputs []types.CoinInput `json:"coininputs"`
	// CoinOutputs defines the coin outputs,
	// which contain the freshly created coins, adding to the total pool of coins
	// available in the rivine network.
	CoinOutputs []types.CoinOutput `json:"coinoutputs"`
	// Minerfees, a fee paid for this coin destruction transaction.
	MinerFees []types.Currency `json:"minerfees,omitempty"`
	// ArbitraryData can be used for any purpose,
	// but is mostly to be used in order to define the reason/origins
	// of the coin creation.
	ArbitraryData []byte `json:"arbitrarydata,omitempty"`
}

CoinDestructionTransaction is to to be used by anyone as a medium in order to destroy coins (coin outputs), partially or complete.

func CoinDestructionTransactionFromTransaction

func CoinDestructionTransactionFromTransaction(tx types.Transaction, expectedVersion types.TransactionVersion) (CoinDestructionTransaction, error)

CoinDestructionTransactionFromTransaction creates a CoinDestructionTransaction, using a regular in-memory rivine transaction.

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

func CoinDestructionTransactionFromTransactionData

func CoinDestructionTransactionFromTransactionData(txData types.TransactionData) (CoinDestructionTransaction, error)

CoinDestructionTransactionFromTransactionData creates a CoinDestructionTransaction, using the TransactionData from a regular in-memory rivine transaction.

func (*CoinDestructionTransaction) Transaction

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

func (*CoinDestructionTransaction) TransactionData

func (cdtx *CoinDestructionTransaction) TransactionData() types.TransactionData

TransactionData returns this CoinDestructionTransaction as regular rivine transaction data.

type CoinDestructionTransactionController

type CoinDestructionTransactionController struct {
	MintingBaseTransactionController

	// TransactionVersion is used to validate/set the transaction version
	// of a coin destruction transaction.
	TransactionVersion types.TransactionVersion
}

CoinDestructionTransactionController defines a rivine-specific transaction controller, for a CoinDestruction Transaction. It allows the destruction of coins.

func (CoinDestructionTransactionController) DecodeTransactionData

func (cdtc CoinDestructionTransactionController) DecodeTransactionData(r io.Reader) (types.TransactionData, error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (CoinDestructionTransactionController) EncodeTransactionData

func (cdtc CoinDestructionTransactionController) EncodeTransactionData(w io.Writer, txData types.TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (CoinDestructionTransactionController) EncodeTransactionIDInput

func (cdtc CoinDestructionTransactionController) EncodeTransactionIDInput(w io.Writer, txData types.TransactionData) error

EncodeTransactionIDInput implements TransactionIDEncoder.EncodeTransactionIDInput

func (CoinDestructionTransactionController) JSONDecodeTransactionData

func (cdtc CoinDestructionTransactionController) JSONDecodeTransactionData(data []byte) (types.TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (CoinDestructionTransactionController) JSONEncodeTransactionData

func (cdtc CoinDestructionTransactionController) JSONEncodeTransactionData(txData types.TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

func (CoinDestructionTransactionController) SignatureHash

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

SignatureHash implements TransactionSignatureHasher.SignatureHash

type MintConditionGetter

type MintConditionGetter interface {
	// GetActiveMintCondition returns the active active mint condition.
	GetActiveMintCondition() (types.UnlockConditionProxy, error)
	// GetMintConditionAt returns the mint condition at a given block height.
	GetMintConditionAt(height types.BlockHeight) (types.UnlockConditionProxy, error)
}

MintConditionGetter allows you to get the mint condition at a given block height.

For the daemon this interface could be implemented directly by the DB object that keeps track of the mint condition state, while for a client this could come via the REST API from a rivine daemon in a more indirect way.

type MinterDefinitionTransaction

type MinterDefinitionTransaction struct {
	// Nonce used to ensure the uniqueness of a MinterDefinitionTransaction's ID and signature.
	Nonce types.TransactionNonce `json:"nonce"`
	// MintFulfillment defines the fulfillment which is used in order to
	// fulfill the globally defined MintCondition.
	MintFulfillment types.UnlockFulfillmentProxy `json:"mintfulfillment"`
	// MintCondition defines a new condition that defines who become(s) the new minter(s),
	// and thus defines who can create coins as well as update who is/are the current minter(s)
	//
	// UnlockHash (unlockhash type 1) and MultiSigConditions are allowed,
	// as well as TimeLocked conditions which have UnlockHash- and MultiSigConditions as
	// internal condition.
	MintCondition types.UnlockConditionProxy `json:"mintcondition"`
	// Minerfees, a fee paid for this minter definition transaction.
	MinerFees []types.Currency `json:"minerfees,omitempty"`
	// ArbitraryData can be used for any purpose,
	// but is mostly to be used in order to define the reason/origins
	// of the transfer of minting power.
	ArbitraryData []byte `json:"arbitrarydata,omitempty"`
}

MinterDefinitionTransaction is to be created only by the defined Coin Minters, as a medium in order to transfer minting powers.

func MinterDefinitionTransactionFromTransaction

func MinterDefinitionTransactionFromTransaction(tx types.Transaction, expectedVersion types.TransactionVersion, requireMinerFees bool) (MinterDefinitionTransaction, error)

MinterDefinitionTransactionFromTransaction creates a MinterDefinitionTransaction, using a regular in-memory rivine transaction.

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

func MinterDefinitionTransactionFromTransactionData

func MinterDefinitionTransactionFromTransactionData(txData types.TransactionData, requireMinerFees bool) (MinterDefinitionTransaction, error)

MinterDefinitionTransactionFromTransactionData creates a MinterDefinitionTransaction, using the TransactionData from a regular in-memory rivine transaction.

func (*MinterDefinitionTransaction) Transaction

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

func (*MinterDefinitionTransaction) TransactionData

func (cctx *MinterDefinitionTransaction) TransactionData() types.TransactionData

TransactionData returns this CoinCreationTransaction as regular rivine transaction data.

type MinterDefinitionTransactionController

type MinterDefinitionTransactionController struct {
	MintingMinerFeeBaseTransactionController

	// MintConditionGetter is used to get a mint condition at the context-defined block height.
	//
	// The found MintCondition defines the condition that has to be fulfilled
	// in order to mint new coins into existence (in the form of non-backed coin outputs).
	MintConditionGetter MintConditionGetter

	// TransactionVersion is used to validate/set the transaction version
	// of a minter definitiontransaction.
	TransactionVersion types.TransactionVersion
}

MinterDefinitionTransactionController defines a rivine-specific transaction controller, for a MinterDefinition Transaction. It allows the transfer of coin minting powers.

func (MinterDefinitionTransactionController) DecodeTransactionData

func (mdtc MinterDefinitionTransactionController) DecodeTransactionData(r io.Reader) (types.TransactionData, error)

DecodeTransactionData implements TransactionController.DecodeTransactionData

func (MinterDefinitionTransactionController) EncodeTransactionData

func (mdtc MinterDefinitionTransactionController) EncodeTransactionData(w io.Writer, txData types.TransactionData) error

EncodeTransactionData implements TransactionController.EncodeTransactionData

func (MinterDefinitionTransactionController) EncodeTransactionIDInput

func (mdtc MinterDefinitionTransactionController) EncodeTransactionIDInput(w io.Writer, txData types.TransactionData) error

EncodeTransactionIDInput implements TransactionIDEncoder.EncodeTransactionIDInput

func (MinterDefinitionTransactionController) GetCommonExtensionData

func (mdtc MinterDefinitionTransactionController) GetCommonExtensionData(extension interface{}) (types.CommonTransactionExtensionData, error)

GetCommonExtensionData implements TransactionCommonExtensionDataGetter.GetCommonExtensionData

func (MinterDefinitionTransactionController) JSONDecodeTransactionData

func (mdtc MinterDefinitionTransactionController) JSONDecodeTransactionData(data []byte) (types.TransactionData, error)

JSONDecodeTransactionData implements TransactionController.JSONDecodeTransactionData

func (MinterDefinitionTransactionController) JSONEncodeTransactionData

func (mdtc MinterDefinitionTransactionController) JSONEncodeTransactionData(txData types.TransactionData) ([]byte, error)

JSONEncodeTransactionData implements TransactionController.JSONEncodeTransactionData

func (MinterDefinitionTransactionController) SignExtension

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

SignExtension implements TransactionExtensionSigner.SignExtension

func (MinterDefinitionTransactionController) SignatureHash

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

SignatureHash implements TransactionSignatureHasher.SignatureHash

type MinterDefinitionTransactionExtension

type MinterDefinitionTransactionExtension struct {
	Nonce           types.TransactionNonce
	MintFulfillment types.UnlockFulfillmentProxy
	MintCondition   types.UnlockConditionProxy
}

MinterDefinitionTransactionExtension defines the MinterDefinitionTx Extension Data

type MintingBaseTransactionController

type MintingBaseTransactionController struct {
	UseLegacySiaEncoding bool
}

MintingBaseTransactionController is the base controller for all minting controllers

type MintingMinerFeeBaseTransactionController

type MintingMinerFeeBaseTransactionController struct {
	MintingBaseTransactionController

	RequireMinerFees bool
}

MintingMinerFeeBaseTransactionController is the base controller for all minting controllers, that require miner fees.

type Plugin

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

Plugin is a struct defines the minting plugin

func NewMintingPlugin

func NewMintingPlugin(genesisMintCondition types.UnlockConditionProxy, minterDefinitionTransactionVersion, coinCreationTransactionVersion types.TransactionVersion, opts *PluginOptions) *Plugin

NewMintingPlugin creates a new Plugin with a genesisMintCondition and correct transaction versions

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) GetActiveMintCondition

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

GetActiveMintCondition implements types.MintConditionGetter.GetActiveMintCondition

func (*Plugin) GetMintConditionAt

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

GetMintConditionAt implements types.MintConditionGetter.GetMintConditionAt

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 transactions to the minting bucket.

func (*Plugin) TransactionValidatorVersionFunctionMapping

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

TransactionValidatorVersionFunctionMapping returns all tx validators linked to this plugin

func (*Plugin) TransactionValidators

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

TransactionValidators returns all tx validators linked to this plugin

type PluginOptions

type PluginOptions struct {
	CoinDestructionTransactionVersion types.TransactionVersion
	UseLegacySiaEncoding              bool
	RequireMinerFees                  bool
}

PluginOptions allows optional parameters to be defined for the minting plugin.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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