proc/worker/client.go
func (w *Worker) ClientPreChannelCreate(job *data.Job) error {
	logger := w.logger.Add("method", "ClientPreChannelCreate", "job", job)

	var jdata ClientPreChannelCreateData
	if err := w.unmarshalDataTo(logger, job.Data, &jdata); err != nil {
		return err
	}

	acc, err := w.accountByPK(logger, jdata.Account)
	if err != nil {
		return err
	}

	offering, err := w.offering(logger, jdata.Offering)
	if err != nil {
		return err
	}

	logger = logger.Add("account", acc, "offering", offering)

	deposit := jdata.Deposit
	if jdata.Deposit == 0 {
		deposit = data.MinDeposit(offering)
	}

	if err := w.checkDeposit(logger, acc, offering, deposit); err != nil {
		return err
	}

	if deposit < data.MinDeposit(offering) {
		return ErrSmallDeposit
	}

	offerHash, err := data.HexToHash(offering.Hash)
	if err != nil {
		logger.Error(err.Error())
		return ErrParseOfferingHash
	}

	err = w.clientPreChannelCreateCheckSupply(logger, offering, offerHash)
	if err != nil {
		return err
	}

	msgRawBytes, err := data.ToBytes(offering.RawMsg)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	msgRaw, _ := messages.UnpackSignature(msgRawBytes)

	msg := offer.Message{}
	if err := json.Unmarshal(msgRaw, &msg); err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	logger = logger.Add("offeringMessage", msg)

	pubkB, err := data.ToBytes(msg.AgentPubKey)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	pubkey, err := crypto.UnmarshalPubkey(pubkB)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	agentEthAddr := data.HexFromBytes(crypto.PubkeyToAddress(*pubkey).Bytes())

	_, err = w.db.FindOneFrom(data.UserTable, "eth_addr", agentEthAddr)
	if err == sql.ErrNoRows {
		err = w.db.Insert(&data.User{
			ID:        util.NewUUID(),
			EthAddr:   agentEthAddr,
			PublicKey: msg.AgentPubKey,
		})
		if err != nil {
			logger.Error(err.Error())
			return ErrInternal
		}
	}

	var gasPrice *big.Int
	if jdata.GasPrice != 0 {
		gasPrice = new(big.Int).SetUint64(jdata.GasPrice)
	}

	return w.clientPreChannelCreateSaveTX(logger,
		job, acc, offering, offerHash, deposit, gasPrice)
}
func (w *Worker) ClientPreChannelCreate(job *data.Job) error {
	logger := w.logger.Add("method", "ClientPreChannelCreate", "job", job)

	var jdata ClientPreChannelCreateData
	if err := w.unmarshalDataTo(logger, job.Data, &jdata); err != nil {
		return err
	}

	acc, err := w.accountByPK(logger, jdata.Account)
	if err != nil {
		return err
	}

	offering, err := w.offering(logger, jdata.Offering)
	if err != nil {
		return err
	}

	logger = logger.Add("account", acc, "offering", offering)

	deposit := jdata.Deposit
	if jdata.Deposit == 0 {
		deposit = data.MinDeposit(offering)
	}

	if err := w.checkDeposit(logger, acc, offering, deposit); err != nil {
		return err
	}

	if deposit < data.MinDeposit(offering) {
		return ErrSmallDeposit
	}

	offerHash, err := data.HexToHash(offering.Hash)
	if err != nil {
		logger.Error(err.Error())
		return ErrParseOfferingHash
	}

	err = w.clientPreChannelCreateCheckSupply(logger, offering, offerHash)
	if err != nil {
		return err
	}

	msgRawBytes, err := data.ToBytes(offering.RawMsg)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	msgRaw, _ := messages.UnpackSignature(msgRawBytes)

	msg := offer.Message{}
	if err := json.Unmarshal(msgRaw, &msg); err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	logger = logger.Add("offeringMessage", msg)

	pubkB, err := data.ToBytes(msg.AgentPubKey)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	pubkey, err := crypto.UnmarshalPubkey(pubkB)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	agentEthAddr := data.HexFromBytes(crypto.PubkeyToAddress(*pubkey).Bytes())

	_, err = w.db.FindOneFrom(data.UserTable, "eth_addr", agentEthAddr)
	if err == sql.ErrNoRows {
		err = w.db.Insert(&data.User{
			ID:        util.NewUUID(),
			EthAddr:   agentEthAddr,
			PublicKey: msg.AgentPubKey,
		})
		if err != nil {
			logger.Error(err.Error())
			return ErrInternal
		}
	}

	var gasPrice *big.Int
	if jdata.GasPrice != 0 {
		gasPrice = new(big.Int).SetUint64(jdata.GasPrice)
	}

	return w.clientPreChannelCreateSaveTX(logger,
		job, acc, offering, offerHash, deposit, gasPrice)
}
func ( w * Worker ) ClientPreChannelCreate ( job * data . Job ) error { logger := w . logger . Add ( " " , " " , " " , job ) var jdata ClientPreChannelCreateData if err := w . unmarshalDataTo ( logger , job . Data , & jdata ) ; err != nil { return err } acc , err := w . accountByPK ( logger , jdata . Account ) if err != nil { return err } offering , err := w . offering ( logger , jdata . Offering ) if err != nil { return err } logger = logger . Add ( " " , acc , " " , offering ) deposit := jdata . Deposit if jdata . Deposit == 0 { deposit = data . MinDeposit ( offering ) } if err := w . checkDeposit ( logger , acc , offering , deposit ) ; err != nil { return err } if deposit < data . MinDeposit ( offering ) { return ErrSmallDeposit } offerHash , err := data . HexToHash ( offering . Hash ) if err != nil { logger . Error ( err . Error ( ) ) return ErrParseOfferingHash } err = w . clientPreChannelCreateCheckSupply ( logger , offering , offerHash ) if err != nil { return err } msgRawBytes , err := data . ToBytes ( offering . RawMsg ) if err != nil { logger . Error ( err . Error ( ) ) return ErrInternal } msgRaw , _ := messages . UnpackSignature ( msgRawBytes ) msg := offer . Message { } if err := json . Unmarshal ( msgRaw , & msg ) ; err != nil { logger . Error ( err . Error ( ) ) return ErrInternal } logger = logger . Add ( " " , msg ) pubkB , err := data . ToBytes ( msg . AgentPubKey ) if err != nil { logger . Error ( err . Error ( ) ) return ErrInternal } pubkey , err := crypto . UnmarshalPubkey ( pubkB ) if err != nil { logger . Error ( err . Error ( ) ) return ErrInternal } agentEthAddr := data . HexFromBytes ( crypto . PubkeyToAddress ( * pubkey ) . Bytes ( ) ) _ , err = w . db . FindOneFrom ( data . UserTable , " " , agentEthAddr ) if err == sql . ErrNoRows { err = w . db . Insert ( & data . User { ID : util . NewUUID ( ) , EthAddr : agentEthAddr , PublicKey : msg . AgentPubKey , } ) if err != nil { logger . Error ( err . Error ( ) ) return ErrInternal } } var gasPrice * big . Int if jdata . GasPrice != 0 { gasPrice = new ( big . Int ) . SetUint64 ( jdata . GasPrice ) } return w . clientPreChannelCreateSaveTX ( logger , job , acc , offering , offerHash , deposit , gasPrice ) }
// ClientPreChannelCreate triggers a channel creation.
ClientPreChannelCreate triggers a channel creation .