Skip to content

Commit

Permalink
fix SetProds in bios to accept string keys or 'ephemeral'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Duchesneau committed Jun 12, 2019
1 parent ea06e9a commit 786f76a
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions bios/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,51 @@ func (op *OpInjectUnregdSnapshot) Actions(b *BIOS) (out []*eos.Action, err error

//

type producerKeyString struct {
ProducerName eos.AccountName `json:"producer_name"`
BlockSigningKeyString string `json:"block_signing_key"`
}

type OpSetProds struct {
Prods []system.ProducerKey
Prods []producerKeyString
}

func (op *OpSetProds) Actions(b *BIOS) (out []*eos.Action, err error) {
// We he can at least process the last few blocks, that wrap up
// and resigns the system accounts.

var prodKeys []system.ProducerKey

for _, key := range op.Prods {
if len(key.BlockSigningKey.Content) == 0 {
key.BlockSigningKey = b.EphemeralPublicKey
prodKey := system.ProducerKey{
ProducerName: key.ProducerName,
}
if key.BlockSigningKeyString == "" || key.BlockSigningKeyString == "ephemeral" {
prodKey.BlockSigningKey = b.EphemeralPublicKey
} else {
k, err := ecc.NewPublicKeyFromData([]byte(key.BlockSigningKeyString))
if err != nil {
panic(err)
}
prodKey.BlockSigningKey = k
}
prodKeys = append(prodKeys, prodKey)
}

if len(op.Prods) == 0 {
op.Prods = []system.ProducerKey{system.ProducerKey{
if len(prodKeys) == 0 {
prodKeys = []system.ProducerKey{system.ProducerKey{
ProducerName: AN("eosio"),
BlockSigningKey: b.EphemeralPublicKey,
}}
}

out = append(out, system.NewSetProds(op.Prods))
var producers []string
for _, key := range prodKeys {
producers = append(producers, string(key.ProducerName))
}
fmt.Printf("Producers set to: %v\n", producers)

out = append(out, system.NewSetProds(prodKeys))
return
}

Expand Down

0 comments on commit 786f76a

Please sign in to comment.