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