github.com/cranelv/ethereum_mpc@v0.0.0-20191031014521-23aeb1415092/mpcService/create_lock_account_mpc.go (about)

     1  package mpcService
     2  
     3  import (
     4  	"github.com/ethereum/go-ethereum/mpcService/protocol"
     5  	"github.com/ethereum/go-ethereum/mpcService/step"
     6  	"github.com/ethereum/go-ethereum/log"
     7  	"github.com/ethereum/go-ethereum/common"
     8  	"github.com/ethereum/go-ethereum/p2p/discover"
     9  )
    10  
    11  //send create LockAccount from leader
    12  func requestCreateLockAccountMpc(hash common.Hash, peers []protocol.PeerInfo,leader *discover.NodeID, preSetValue ...protocol.MpcValue) (*MpcContext, error) {
    13  	result := createMpcBaseMpcResult()
    14  	result.Initialize(preSetValue...)
    15  	mpc := createMpcContext(hash,peers,leader, result)
    16  	requestMpc := step.CreateRequestMpcStep(result,mpc.NodeInfo, protocol.MpcCreateLockAccountLeader)
    17  	mpcReady := step.CreateMpcReadyStep(result,mpc.NodeInfo)
    18  	return generateCreateLockAccountMpc(mpc,result, requestMpc, mpcReady)
    19  
    20  }
    21  
    22  //get message from leader and create Context
    23  func acknowledgeCreateLockAccountMpc(hash common.Hash, peers []protocol.PeerInfo,leader *discover.NodeID, preSetValue ...protocol.MpcValue) (*MpcContext, error) {
    24  	log.Info("acknowledgeCreateLockAccountMpc begin.")
    25  
    26  	result := createMpcBaseMpcResult()
    27  	result.Initialize(preSetValue...)
    28  	mpc := createMpcContext(hash, peers, leader,result)
    29  	AcknowledgeMpc := step.CreateAcknowledgeMpcStep(result,mpc.NodeInfo, protocol.MpcCreateLockAccountPeer)
    30  	mpcReady := step.CreateGetMpcReadyStep(result,mpc.NodeInfo)
    31  	return generateCreateLockAccountMpc(mpc, result,AcknowledgeMpc, mpcReady)
    32  }
    33  
    34  func generateCreateLockAccountMpc(mpc *MpcContext,result protocol.MpcResultInterface, firstStep protocol.MpcStepFunc, readyStep protocol.MpcStepFunc) (*MpcContext, error) {
    35  	JRSS := step.CreateMpcJRSS_Step(result,protocol.MPCDegree, mpc.NodeInfo)
    36  	PublicKey := step.CreateMpcAddressStep(result,mpc.NodeInfo)
    37  	ackAddress := step.CreateAckMpcAccountStep(result,mpc.NodeInfo)
    38  	mpc.setMpcStep(firstStep, readyStep, JRSS, PublicKey, ackAddress)
    39  	return mpc, nil
    40  }