dev

package
v0.0.0-...-eb4c3ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//err code 1
	ErrEncodeSendMsgFail      = `{Code:1,Error:"encode send msg fail."}`
	ErrParamError             = `{Code:2,Error:"parameters error."}`
	ErrGetOtherNodesDataFail  = `{Code:3,Error:"NetWork Error,Get Data From Other Node Fail."}`
	ErrUnknownChType          = `{Code:4,Error:"unknown channel type."}`
	ErrGetChValueFail         = `{Code:5,Error:"get channel value fail."}`
	ErrNoFindWorker           = `{Code:7,Error:"can not find worker."}`
	ErrGetWorkerIdError       = `{Code:10,Error:"get worker id error."}`
	ErrGetPrexDataError       = `{Code:11,Error:"get msg prefix data error."}`
	ErrSendDataToGroupFail    = `{Code:15,Error:"send data to group fail."}`
	ErrInternalMsgFormatError = `{Code:16,Error:"msg data format error."}`
	ErrGetNoResFromGroupMem   = `{Code:17,Error:"no get any result from other group node."}`
	ErrCoinTypeNotSupported   = `{Code:18,Error:"coin type is not supported."}`
	ErrGroupNotReady          = `{Code:23,Error:"the group is not ready.please try again."}`
	ErrGetGenPubkeyFail       = `{Code:24,Error:"get generate pubkey fail."}`
	ErrGetGenSaveDataFail     = `{Code:25,Error:"get generate save data fail."}`
	ErrCreateDbFail           = `{Code:26,Error:"create db fail."}`
	ErrDcrmSigWrongSize       = `{Code:28,Error:"wrong size for dcrm sig."}`
	ErrDcrmSigFail            = `{Code:29,Error:"dcrm sign fail."}`
	ErrInvalidDcrmAddr        = `{Code:30,Error:"invalid dcrm address."}`
	ErrGetRealEosUserFail     = `{Code:27,Error:"cannot get real eos account."}`
	ErrSendTxToNetFail        = `{Code:14,Error:"send tx to outside net fail."}`
	ErrGetC1Timeout           = `{Code:31,Error:"get C1 timeout."}`
	ErrGetEnodeByUIdFail      = `{Code:32,Error:"can not find proper enodes by uid."}`
	ErrGetD1Timeout           = `{Code:33,Error:"get D1 timeout."}`
	ErrGetSHARE1Timeout       = `{Code:34,Error:"get SHARE1 timeout."}`
	ErrGetAllSHARE1Fail       = `{Code:35,Error:"get all SHARE1 msg fail."}`
	ErrGetAllD1Fail           = `{Code:36,Error:"get all D1 msg fail."}`
	ErrVerifySHARE1Fail       = `{Code:37,Error:"verify SHARE1 fail."}`
	ErrGetAllC1Fail           = `{Code:38,Error:"get all C1 msg fail."}`
	ErrKeyGenVerifyCommitFail = `{Code:39,Error:"verify commit in keygenerate fail."}`
	ErrGetZKFACTPROOFTimeout  = `{Code:40,Error:""get ZKFACTPROOF timeout."}`
	ErrGetZKUPROOFTimeout     = `{Code:41,Error:""get ZKUPROOF timeout."}`
	ErrGetAllZKFACTPROOFFail  = `{Code:42,Error:"get all ZKFACTPROOF msg fail."}`
	ErrVerifyZKFACTPROOFFail  = `{Code:43,Error:"verify ZKFACTPROOF fail."}`
	ErrGetAllZKUPROOFFail     = `{Code:44,Error:"get all ZKUPROOF msg fail."}`
	ErrVerifyZKUPROOFFail     = `{Code:45,Error:"verify ZKUPROOF fail."}`
	ErrGetC11Timeout          = `{Code:46,Error:"get C11 timeout."}`
	ErrGetMTAZK1PROOFTimeout  = `{Code:47,Error:"get MTAZK1PROOF timeout."}`
	ErrGetKCTimeout           = `{Code:48,Error:"get KC timeout."}`
	ErrGetAllKCFail           = `{Code:49,Error:"get all KC msg fail."}`
	ErrGetAllMTAZK1PROOFFail  = `{Code:50,Error:"get all MTAZK1PROOF msg fail."}`
	ErrVerifyMTAZK1PROOFFail  = `{Code:51,Error:"verify MTAZK1PROOF fail.""}`
	ErrGetMKGTimeout          = `{Code:52,Error:"get MKG timeout."}`
	ErrGetAllMKGFail          = `{Code:53,Error:"get all MKG msg fail."}`
	ErrGetMKWTimeout          = `{Code:54,Error:"get MKW timeout."}`
	ErrGetAllMKWFail          = `{Code:55,Error:"get all MKW msg fail."}`
	ErrVerifyMKGFail          = `{Code:56,Error:"verify MKG fail.""}`
	ErrVerifyMKWFail          = `{Code:57,Error:"verify MKW fail.""}`
	ErrGetPaillierPrivKeyFail = `{Code:58,Error:"get paillier privkey fail.""}`
	ErrGetDELTA1Timeout       = `{Code:59,Error:"get DELTA1 timeout."}`
	ErrGetAllDELTA1Fail       = `{Code:60,Error:"get all DELTA1 msg fail."}`
	ErrGetD11Timeout          = `{Code:61,Error:"get D11 timeout."}`
	ErrGetAllD11Fail          = `{Code:62,Error:"get all D11 msg fail."}`
	ErrGetAllC11Fail          = `{Code:63,Error:"get all C11 msg fail."}`
	ErrSignVerifyCommitFail   = `{Code:64,Error:"verify commit in dcrm sign fail."}`
	ErrREqualZero             = `{Code:65,Error:"sign error: r equal zero."}`
	ErrGetS1Timeout           = `{Code:66,Error:"get S1 timeout."}`
	ErrGetAllS1Fail           = `{Code:67,Error:"get all S1 msg fail."}`
	ErrVerifySAllFail         = `{Code:68,Error:"verify SAll != m*G + r*PK in dcrm sign ec2."}`
	ErrGetSS1Timeout          = `{Code:69,Error:"get SS1 timeout."}`
	ErrGetAllSS1Fail          = `{Code:70,Error:"get all SS1 msg fail."}`
	ErrSEqualZero             = `{Code:71,Error:"sign error: s equal zero."}`
	ErrDcrmSignVerifyFail     = `{Code:72,Error:"dcrm sign verify fail."}`
)

dcrm erros

View Source
var (
	Sep     = "dcrmparm"
	SepSave = "dcrmsepsave"
	SepSg   = "dcrmmsg"
	SepDel  = "dcrmsepdel"

	PaillierKeyLength = 2048

	//callback
	GetGroup               func(string) (int, string)
	SendToGroupAllNodes    func(string, string) (string, error)
	GetSelfEnode           func() string
	BroadcastInGroupOthers func(string, string) (string, error)
	SendToPeer             func(string, string) error
	ParseNode              func(string) string
	GetEosAccount          func() (string, string, string)

	PubKeyDataChan    = make(chan KeyData, 1000)
	GetPubKeyDataChan = make(chan chan []*PubKeyData, 1000)
	KeyFile           string
	AllAccounts       = make([]*PubKeyData, 0)
	LdbReqAddr        = make(map[string][]byte)
	LdbLockOut        = make(map[string][]byte)
	LdbPubKeyData     = make(map[string][]byte)
)
View Source
var (
	//rpc-req //dcrm node
	RpcMaxWorker = 2000
	RpcMaxQueue  = 2000
	RpcReqQueue  chan RpcReq

	Enode_cnts int
	NodeCnt    = 3
	ThresHold  = 3
)

//////////////////////dcrm///////////////////////////////

Functions

func AcceptLockOut

func AcceptLockOut(account string, groupid string, nonce string, dcrmfrom string, threshold string, deal bool, accept string, status string, outhash string, tip string, errinfo string, allreply string) (string, error)

func AcceptReqAddr

func AcceptReqAddr(account string, cointype string, groupid string, nonce string, threshold string, mode string, deal bool, accept string, status string, pubkey string, tip string, errinfo string, allreply string) (string, error)

if accept == "",don't set Accept if status == "",don't set Status if pubkey == "",don't set PubKey if tip == "",don't set Tip if errinfo == "",don't set ErrInfo if allreply == "",don't set AllReply

func AcceptReqAddr(account string,cointype string,groupid string,nonce string,threshold string,mode string,deal bool,accept string,status string,pubkey string,tip string,errinfo string,allreply string) (string,error) {
    lock5.Lock()
    dir := GetAcceptReqAddrDir()
    db,err := ethdb.NewLDBDatabase(dir, 0, 0)
    //bug
    if err != nil {
	for i:=0;i<1000;i++ {
	    db,err = ethdb.NewLDBDatabase(dir, 0, 0)
	    if err == nil {
		break
	    }

	    time.Sleep(time.Duration(1000000))
	}
    }
    //
    if err != nil {
        lock5.Unlock()
	return "dcrm back-end internal error:open level db fail",err
    }

    key := Keccak256Hash([]byte(strings.ToLower(account + ":" + cointype + ":" + groupid + ":" + nonce + ":" + threshold + ":" + mode))).Hex()
    da,err := db.Get([]byte(key))
    ///////
    if err != nil {
	db.Close()
	lock5.Unlock()
	return "dcrm back-end internal error:get accept data fail from db",err
    }

    ds,err := UnCompress(string(da))
    if err != nil {
	db.Close()
	lock5.Unlock()
	return "dcrm back-end internal error:uncompress accept data fail",err
    }

    dss,err := Decode2(ds,"AcceptReqAddrData")
    if err != nil {
	db.Close()
	lock5.Unlock()
	return "dcrm back-end internal error:decode accept data fail",err
    }

    ac := dss.(*AcceptReqAddrData)
    ac.Deal = deal
    if accept != "" {
	ac.Accept = accept
    }
    if pubkey != "" {
	ac.PubKey = pubkey
    }
    if tip != "" {
	ac.Tip = tip
    }
    if errinfo != "" {
	ac.Error = errinfo
    }
    if status != "" {
	ac.Status = status
    }
    if allreply != "" {
	ac.AllReply = allreply
    }

    e,err := Encode2(ac)
    if err != nil {
	db.Close()
	lock5.Unlock()
	return "dcrm back-end internal error:encode accept data fail",err
    }

    es,err := Compress([]byte(e))
    if err != nil {
	db.Close()
	lock5.Unlock()
	return "dcrm back-end internal error:compress accept data fail",err
    }

    db.Put([]byte(key),[]byte(es))
    db.Close()
    lock5.Unlock()
    acceptReqAddrChan <- account
    return "",nil
}

func Call

func Call(msg interface{}, enode string)

func ClearChan

func ClearChan(ch chan string)

func Compress

func Compress(c []byte) (string, error)

//compress

func DcrmCall

func DcrmCall(msg interface{}, enode string) <-chan string

func DcrmCallRet

func DcrmCallRet(msg interface{}, enode string)

func Decode2

func Decode2(s string, datatype string) (interface{}, error)

func DecryptMsg

func DecryptMsg(cm string) (string, error)

func DefaultDataDir

func DefaultDataDir() string

func DisMsg

func DisMsg(msg string)

msg: hash-enode:C1:X1:X2

func DoubleHash

func DoubleHash(id string, cointype string) *big.Int

func EdVerify

func EdVerify(input InputVerify) bool

func Encode2

func Encode2(obj interface{}) (string, error)

func EncryptMsg

func EncryptMsg(msg string, enodeID string) (string, error)

/

func Find

func Find(l *list.List, msg string) bool

func GetAcceptLockOutDir

func GetAcceptLockOutDir() string

func GetAcceptLockOutRes

func GetAcceptLockOutRes(account string, groupid string, nonce string, dcrmfrom string, threshold string) (string, bool)

func GetAcceptReqAddrDir

func GetAcceptReqAddrDir() string

func GetAcceptReqAddrRes

func GetAcceptReqAddrRes(account string, cointype string, groupid string, nonce string, threshold string, mode string) (string, bool)

func GetAccounts

func GetAccounts(gid, mode string) (interface{}, string, error)

func GetAllPubKeyDataFromDb

func GetAllPubKeyDataFromDb()

func GetChannelValue

func GetChannelValue(t int, obj interface{}) (string, string, error)

func GetDbDir

func GetDbDir() string

func GetEnodesByUid

func GetEnodesByUid(uid *big.Int, cointype string, groupid string) string

func GetEnodesInfo

func GetEnodesInfo(GroupId string)

func GetEosDbDir

func GetEosDbDir() string

eos_init---> eos account key: crypto.Keccak256Hash([]byte("eossettings")) value: pubkey+eos account

func GetGroupDir

func GetGroupDir() string

func GetIds

func GetIds(cointype string, groupid string) sortableIDSSlice

func GetLockOutNonce

func GetLockOutNonce(account string, cointype string, dcrmaddr string) (string, string, error)

func GetLockOutReply

func GetLockOutReply() (string, string, error)

func GetLockOutStatus

func GetLockOutStatus(key string) (string, string, error)

func GetPaillierPk

func GetPaillierPk(save string, index int) *ec2.PublicKey

func GetPaillierSk

func GetPaillierSk(save string, index int) *ec2.PrivateKey

func GetRandomInt

func GetRandomInt(length int) *big.Int

func GetRandomIntFromZn

func GetRandomIntFromZn(n *big.Int) *big.Int

func GetReqAddrNonce

func GetReqAddrNonce(account string) (string, string, error)

func GetReqAddrReply

func GetReqAddrReply() (string, string, error)

func GetReqAddrStatus

func GetReqAddrStatus(key string) (string, string, error)

func GetRetErr

func GetRetErr(err string) error

func GetRetErrJsonStr

func GetRetErrJsonStr(code int, err string) string

func GetSignString

func GetSignString(r *big.Int, s *big.Int, v int32, i int) string

func GetZkFactProof

func GetZkFactProof(save string, index int) *ec2.ZkFactProof

func InitChan

func InitChan()

workers,RpcMaxWorker,RpcReqWorker,RpcReqQueue,RpcMaxQueue,ReqDispatcher

func InitDev

func InitDev(keyfile string, groupId string)

func IsCurNode

func IsCurNode(enodes string, cur string) bool

func IsInGroup

func IsInGroup(enode string, groupId string) bool

func KeyGenerate_ec2

func KeyGenerate_ec2(msgprex string, ch chan interface{}, id int, cointype string) bool

ec2 msgprex = hash

func KeyGenerate_ed

func KeyGenerate_ed(msgprex string, ch chan interface{}, id int, cointype string) bool

ed msgprex = hash

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.

func RegDcrmGetEosAccountCallBack

func RegDcrmGetEosAccountCallBack(f func() (string, string, string))

func RegP2pBroadcastInGroupOthersCallBack

func RegP2pBroadcastInGroupOthersCallBack(f func(string, string) (string, error))

func RegP2pGetGroupCallBack

func RegP2pGetGroupCallBack(f func(string) (int, string))

func RegP2pGetSelfEnodeCallBack

func RegP2pGetSelfEnodeCallBack(f func() string)

func RegP2pParseNodeCallBack

func RegP2pParseNodeCallBack(f func(string) string)

func RegP2pSendMsgToPeerCallBack

func RegP2pSendMsgToPeerCallBack(f func(string, string) error)

func RegP2pSendToGroupAllNodesCallBack

func RegP2pSendToGroupAllNodesCallBack(f func(string, string) (string, error))

func SaveAcceptLockOutData

func SaveAcceptLockOutData(ac *AcceptLockOutData) error

func SaveAcceptReqAddrData

func SaveAcceptReqAddrData(ac *AcceptReqAddrData) error

func SavePubKeyDataToDb

func SavePubKeyDataToDb()

func SendMsgToDcrmGroup

func SendMsgToDcrmGroup(msg string, groupid string)

func SendMsgToPeer

func SendMsgToPeer(enodes string, msg string)

func SendReqToGroup

func SendReqToGroup(msg string, rpctype string) (string, string, error)

func SetLockOutNonce

func SetLockOutNonce(account string, cointype string, dcrmaddr string, nonce string) (string, error)

func SetReqAddrNonce

func SetReqAddrNonce(account string, nonce string) (string, error)

func SetUpMsgList

func SetUpMsgList(msg string)

func Sign_ec2

func Sign_ec2(msgprex string, save string, message string, cointype string, pkx *big.Int, pky *big.Int, ch chan interface{}, id int) string

msgprex = hash return value is the backup for the dcrm sig

func Sign_ed

func Sign_ed(msgprex string, save string, message string, cointype string, pk string, ch chan interface{}, id int) string

msgprex = hash return value is the backup for the dcrm sig

func Tool_DecimalByteSlice2HexString

func Tool_DecimalByteSlice2HexString(DecimalSlice []byte) string

func UnCompress

func UnCompress(s string) (string, error)

//uncompress

func Verify

func Verify(r *big.Int, s *big.Int, v int32, message string, pkx *big.Int, pky *big.Int) bool

func Verify2

func Verify2(r *big.Int, s *big.Int, v int32, message string, pkx *big.Int, pky *big.Int) bool

Types

type AcceptLockOutData

type AcceptLockOutData struct {
	Account  string
	GroupId  string
	Nonce    string
	DcrmFrom string
	DcrmTo   string
	Value    string
	Cointype string
	LimitNum string
	Mode     string

	Deal   bool
	Accept string

	Status    string
	OutTxHash string
	Tip       string
	Error     string

	AllReply string
}

type AcceptReqAddrData

type AcceptReqAddrData struct {
	Account  string
	Cointype string
	GroupId  string
	Nonce    string
	LimitNum string
	Mode     string

	Deal   bool
	Accept string

	Status string
	PubKey string
	Tip    string
	Error  string

	AllReply string
}

type AccountsList

type AccountsList struct {
	GroupID  string
	Accounts []string
}

type DcrmHash

type DcrmHash [32]byte

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (h DcrmHash)

Keccak256Hash calculates and returns the Keccak256 hash of the input data, converting it to an internal Hash data structure.

func (DcrmHash) Hex

func (h DcrmHash) Hex() string

type ECDSASignature

type ECDSASignature struct {
	// contains filtered or unexported fields
}

func (*ECDSASignature) GetR

func (this *ECDSASignature) GetR() *big.Int

func (*ECDSASignature) GetRecoveryParam

func (this *ECDSASignature) GetRecoveryParam() int32

func (*ECDSASignature) GetRoudFiveAborted

func (this *ECDSASignature) GetRoudFiveAborted() bool

func (*ECDSASignature) GetS

func (this *ECDSASignature) GetS() *big.Int

func (*ECDSASignature) New

func (this *ECDSASignature) New()

func (*ECDSASignature) New2

func (this *ECDSASignature) New2(r *big.Int, s *big.Int)

func (*ECDSASignature) New3

func (this *ECDSASignature) New3(r *big.Int, s *big.Int, recoveryParam int32)

func (*ECDSASignature) SetR

func (this *ECDSASignature) SetR(r *big.Int)

func (*ECDSASignature) SetRecoveryParam

func (this *ECDSASignature) SetRecoveryParam(recoveryParam int32)

func (*ECDSASignature) SetRoudFiveAborted

func (this *ECDSASignature) SetRoudFiveAborted(roudFiveAborted bool)

func (*ECDSASignature) SetS

func (this *ECDSASignature) SetS(s *big.Int)

type Err

type Err struct {
	Info string
}

error type 1

func (Err) Error

func (e Err) Error() string

type ErrorRet

type ErrorRet struct {
	Code  int
	Error string
}

type GetLockOutReplySendMsgToDcrm

type GetLockOutReplySendMsgToDcrm struct {
}

func (*GetLockOutReplySendMsgToDcrm) Run

func (self *GetLockOutReplySendMsgToDcrm) Run(workid int, ch chan interface{}) bool

type GetReqAddrReplySendMsgToDcrm

type GetReqAddrReplySendMsgToDcrm struct {
}

func (*GetReqAddrReplySendMsgToDcrm) Run

func (self *GetReqAddrReplySendMsgToDcrm) Run(workid int, ch chan interface{}) bool

type InputVerify

type InputVerify struct {
	FinalR  [32]byte
	FinalS  [32]byte
	Message []byte
	FinalPk [32]byte
}

type KeyData

type KeyData struct {
	Key  []byte
	Data string
}

type LockOutReply

type LockOutReply struct {
	Enode string
	Reply string
}

type LockOutReplys

type LockOutReplys struct {
	Replys []LockOutReply
}

type LockOutSendMsgToDcrm

type LockOutSendMsgToDcrm struct {
	Account  string
	DcrmFrom string
	DcrmTo   string
	Value    string
	Cointype string
	GroupId  string
	Nonce    string
	LimitNum string
	Mode     string
}

msg = fusionaccount:dcrmaddr:dcrmto:value:cointype:groupid:nonce:threshold

func (*LockOutSendMsgToDcrm) Run

func (self *LockOutSendMsgToDcrm) Run(workid int, ch chan interface{}) bool

type LockOutStatus

type LockOutStatus struct {
	Status    string
	OutTxHash string
	Tip       string
	Error     string
	AllReply  string
}

type PubAccounts

type PubAccounts struct {
	Group []AccountsList
}

type PubKeyData

type PubKeyData struct {
	Pub      string
	Save     string
	Nonce    string
	GroupId  string
	LimitNum string
	Mode     string
}

type RecvMsg

type RecvMsg struct {
	// contains filtered or unexported fields
}

RecvMsg

func (*RecvMsg) Run

func (self *RecvMsg) Run(workid int, ch chan interface{}) bool

type ReqAddrSendMsgToDcrm

type ReqAddrSendMsgToDcrm struct {
	Account  string
	Cointype string
	GroupId  string
	Nonce    string
	LimitNum string
	Mode     string
}

func (*ReqAddrSendMsgToDcrm) Run

func (self *ReqAddrSendMsgToDcrm) Run(workid int, ch chan interface{}) bool

type ReqDispatcher

type ReqDispatcher struct {
	// A pool of workers channels that are registered with the dispatcher
	WorkerPool chan chan RpcReq
}

rpc-req

func NewReqDispatcher

func NewReqDispatcher(maxWorkers int) *ReqDispatcher

func (*ReqDispatcher) Run

func (d *ReqDispatcher) Run()

type RpcDcrmRes

type RpcDcrmRes struct {
	Ret string
	Tip string
	Err error
}

func GetGroupRes

func GetGroupRes(wid int) RpcDcrmRes

type RpcReq

type RpcReq struct {
	// contains filtered or unexported fields
}

type RpcReqWorker

type RpcReqWorker struct {
	RpcReqWorkerPool chan chan RpcReq
	RpcReqChannel    chan RpcReq
	// contains filtered or unexported fields
}

func FindWorker

func FindWorker(sid string) (*RpcReqWorker, error)

func NewRpcReqWorker

func NewRpcReqWorker(workerPool chan chan RpcReq) *RpcReqWorker

func (*RpcReqWorker) Clear

func (w *RpcReqWorker) Clear()

func (*RpcReqWorker) Clear2

func (w *RpcReqWorker) Clear2()

func (*RpcReqWorker) Start

func (w *RpcReqWorker) Start()

func (*RpcReqWorker) Stop

func (w *RpcReqWorker) Stop()

type SendMsg

type SendMsg struct {
	MsgType string
	Nonce   string
	WorkId  int
	Msg     string
}

type WorkReq

type WorkReq interface {
	Run(workid int, ch chan interface{}) bool
}

Directories

Path Synopsis
lib
ec2
ed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL