github.com/koko1123/flow-go-1@v0.29.6/engine/access/rest/request/proposal_key.go (about)

     1  package request
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/koko1123/flow-go-1/engine/access/rest/models"
     7  	"github.com/koko1123/flow-go-1/engine/access/rest/util"
     8  	"github.com/koko1123/flow-go-1/model/flow"
     9  )
    10  
    11  type ProposalKey flow.ProposalKey
    12  
    13  func (p *ProposalKey) Parse(raw models.ProposalKey) error {
    14  	var address Address
    15  	err := address.Parse(raw.Address)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	keyIndex, err := util.ToUint64(raw.KeyIndex)
    21  	if err != nil {
    22  		return fmt.Errorf("invalid key index: %w", err)
    23  	}
    24  
    25  	seqNumber, err := util.ToUint64(raw.SequenceNumber)
    26  	if err != nil {
    27  		return fmt.Errorf("invalid sequence number: %w", err)
    28  	}
    29  
    30  	*p = ProposalKey(flow.ProposalKey{
    31  		Address:        address.Flow(),
    32  		KeyIndex:       keyIndex,
    33  		SequenceNumber: seqNumber,
    34  	})
    35  	return nil
    36  }
    37  
    38  func (p ProposalKey) Flow() flow.ProposalKey {
    39  	return flow.ProposalKey(p)
    40  }