github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/txs/payload/gov_tx.go (about)

     1  package payload
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hyperledger/burrow/acm/balance"
     7  	"github.com/hyperledger/burrow/crypto"
     8  	spec "github.com/hyperledger/burrow/genesis/spec"
     9  	permission "github.com/hyperledger/burrow/permission"
    10  )
    11  
    12  // GovernanceTx contains functionality for altering permissions, token distribution, consensus parameters,
    13  // validators, and network forks.
    14  
    15  func (tx *GovTx) Type() Type {
    16  	return TypeGovernance
    17  }
    18  
    19  func (tx *GovTx) GetInputs() []*TxInput {
    20  	return tx.Inputs
    21  }
    22  
    23  func (tx *GovTx) String() string {
    24  	return fmt.Sprintf("GovTx{%v -> %v}", tx.Inputs, tx.AccountUpdates)
    25  }
    26  
    27  func (tx *GovTx) Any() *Any {
    28  	return &Any{
    29  		GovTx: tx,
    30  	}
    31  }
    32  
    33  // TODO:
    34  // - Set validator power
    35  // - Set account amount(s)
    36  // - Set account permissions
    37  // - Set global permissions
    38  // - Set ConsensusParams
    39  // Future considerations:
    40  // - Handle network forks/termination/merging/replacement ?
    41  // - Provide transaction in stasis/sudo (voting?)
    42  // - Handle bonding by other means (e.g. pre-shared key permitting n bondings)
    43  // - Network administered proxies (i.e. instead of keys have password authentication for identities - allow calls to originate as if from address without key?)
    44  // Subject to:
    45  // - Less than 1/3 validator power change per block
    46  
    47  // Creates a GovTx that alters the validator power of id to the power passed
    48  func AlterPowerTx(inputAddress crypto.Address, id crypto.Addressable, power uint64) *GovTx {
    49  	return AlterBalanceTx(inputAddress, id, balance.New().Power(power))
    50  }
    51  
    52  func AlterBalanceTx(inputAddress crypto.Address, id crypto.Addressable, bal balance.Balances) *GovTx {
    53  	publicKey := id.GetPublicKey()
    54  	return UpdateAccountTx(inputAddress, &spec.TemplateAccount{
    55  		PublicKey: publicKey,
    56  		Amounts:   bal,
    57  	})
    58  }
    59  
    60  func AlterPermissionsTx(inputAddress crypto.Address, id crypto.Addressable, perms permission.PermFlag) *GovTx {
    61  	address := id.GetAddress()
    62  	return UpdateAccountTx(inputAddress, &spec.TemplateAccount{
    63  		Address:     &address,
    64  		Permissions: permission.PermFlagToStringList(perms),
    65  	})
    66  }
    67  
    68  func UpdateAccountTx(inputAddress crypto.Address, updates ...*spec.TemplateAccount) *GovTx {
    69  	return &GovTx{
    70  		Inputs: []*TxInput{{
    71  			Address: inputAddress,
    72  		}},
    73  		AccountUpdates: updates,
    74  	}
    75  }