github.com/iotexproject/iotex-core@v1.14.1-rc1/action/action_deserializer.go (about)

     1  // Copyright (c) 2022 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package action
     7  
     8  import "github.com/iotexproject/iotex-proto/golang/iotextypes"
     9  
    10  // Deserializer de-serializes an action
    11  //
    12  // It's a wrapper to set certain parameters in order to correctly de-serialize an action
    13  // Currently the parameter is EVM network ID for tx in web3 format, it is called like
    14  //
    15  // act, err := (&Deserializer{}).SetEvmNetworkID(id).ActionToSealedEnvelope(pbAction)
    16  type Deserializer struct {
    17  	evmNetworkID uint32
    18  }
    19  
    20  // SetEvmNetworkID sets the evm network ID for web3 actions
    21  func (ad *Deserializer) SetEvmNetworkID(id uint32) *Deserializer {
    22  	ad.evmNetworkID = id
    23  	return ad
    24  }
    25  
    26  // ActionToSealedEnvelope converts protobuf to SealedEnvelope
    27  func (ad *Deserializer) ActionToSealedEnvelope(pbAct *iotextypes.Action) (*SealedEnvelope, error) {
    28  	var selp SealedEnvelope
    29  	err := selp.loadProto(pbAct, ad.evmNetworkID)
    30  	return &selp, err
    31  }