Skip to content

Commit

Permalink
Added producer protocol feature support
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeless committed Jul 23, 2020
1 parent 2b67efe commit 2c1feaa
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api.go
Expand Up @@ -145,6 +145,15 @@ func (api *API) IsProducerPaused(ctx context.Context) (out bool, err error) {
return
}

func (api *API) GetProducerProtocolFeatures(ctx context.Context) (out []ProtocolFeature, err error) {
err = api.call(ctx, "producer", "get_supported_protocol_features", nil, &out)
return
}

func (api *API) ScheduleProducerProtocolFeatureActivations(ctx context.Context, protocolFeaturesToActivate []Checksum256) error {
return api.call(ctx, "producer", "schedule_protocol_feature_activations", M{"protocol_features_to_activate": protocolFeaturesToActivate}, nil)
}

func (api *API) GetAccount(ctx context.Context, name AccountName) (out *AccountResp, err error) {
err = api.call(ctx, "chain", "get_account", M{"account_name": name}, &out)
return
Expand Down
20 changes: 20 additions & 0 deletions responses.go
Expand Up @@ -173,6 +173,26 @@ type SequencedTransactionResp struct {
TransactionResp
}

type ProtocolFeature struct {
FeatureDigest Checksum256 `json:"feature_digest"`
SubjectiveRestriction SubjectiveRestriction `json:"subjective_restrictions"`
DescriptionDigest Checksum256 `json:"description_digest"`
Dependencies []Checksum256 `json:"dependencies"`
ProtocolFeatureType string `json:"protocol_feature_type"`
Specification []ProtocolFeatureSpecification `json:"specification"`
}

type SubjectiveRestriction struct {
Enabled bool `json:"enabled"`
PreactivationRequired bool `json:"preactivation_required"`
EarliestAllowedActivationTime JSONTime `json:"earliest_allowed_activation_time"`
}

type ProtocolFeatureSpecification struct {
Name string `json:"name"`
Value string `json:"value"`
}

type TransactionsResp struct {
Transactions []SequencedTransactionResp
}
Expand Down
112 changes: 112 additions & 0 deletions system/activatefeature.go
@@ -0,0 +1,112 @@
package system

import (
"github.com/eoscanada/eos-go"
"github.com/eoscanada/eos-go/ecc"
)

func NewNewAccount(creator, newAccount eos.AccountName, publicKey ecc.PublicKey) *eos.Action {
return &eos.Action{
Account: AN("eosio"),
Name: ActN("newaccount"),
Authorization: []eos.PermissionLevel{
{Actor: creator, Permission: PN("active")},
},
ActionData: eos.NewActionData(NewAccount{
Creator: creator,
Name: newAccount,
Owner: eos.Authority{
Threshold: 1,
Keys: []eos.KeyWeight{
{
PublicKey: publicKey,
Weight: 1,
},
},
Accounts: []eos.PermissionLevelWeight{},
},
Active: eos.Authority{
Threshold: 1,
Keys: []eos.KeyWeight{
{
PublicKey: publicKey,
Weight: 1,
},
},
Accounts: []eos.PermissionLevelWeight{},
},
}),
}
}

// NewDelegatedNewAccount returns a `newaccount` action that lives on the
// `eosio.system` contract. It is filled with an authority structure that
// delegates full control of the new account to an already existing account.
func NewDelegatedNewAccount(creator, newAccount eos.AccountName, delegatedTo eos.AccountName) *eos.Action {
return &eos.Action{
Account: AN("eosio"),
Name: ActN("newaccount"),
Authorization: []eos.PermissionLevel{
{Actor: creator, Permission: PN("active")},
},
ActionData: eos.NewActionData(NewAccount{
Creator: creator,
Name: newAccount,
Owner: eos.Authority{
Threshold: 1,
Keys: []eos.KeyWeight{},
Accounts: []eos.PermissionLevelWeight{
eos.PermissionLevelWeight{
Permission: eos.PermissionLevel{
Actor: delegatedTo,
Permission: PN("active"),
},
Weight: 1,
},
},
},
Active: eos.Authority{
Threshold: 1,
Keys: []eos.KeyWeight{},
Accounts: []eos.PermissionLevelWeight{
eos.PermissionLevelWeight{
Permission: eos.PermissionLevel{
Actor: delegatedTo,
Permission: PN("active"),
},
Weight: 1,
},
},
},
}),
}
}

// NewCustomNewAccount returns a `newaccount` action that lives on the
// `eosio.system` contract. You can specify your own `owner` and
// `active` permissions.
func NewCustomNewAccount(creator, newAccount eos.AccountName, owner, active eos.Authority) *eos.Action {
return &eos.Action{
Account: AN("eosio"),
Name: ActN("newaccount"),
Authorization: []eos.PermissionLevel{
{Actor: creator, Permission: PN("active")},
},
ActionData: eos.NewActionData(NewAccount{
Creator: creator,
Name: newAccount,
Owner: owner,
Active: active,
}),
}
}

// NewAccount represents a `newaccount` action on the `eosio.system`
// contract. It is one of the rare ones to be hard-coded into the
// blockchain.
type NewAccount struct {
Creator eos.AccountName `json:"creator"`
Name eos.AccountName `json:"name"`
Owner eos.Authority `json:"owner"`
Active eos.Authority `json:"active"`
}

0 comments on commit 2c1feaa

Please sign in to comment.