MCPcopy Create free account
hub / github.com/CPChain/chain / NewID

Function NewID

api/rpc/utils.go:205–226  ·  view source on GitHub ↗

NewID generates a identifier that can be used as an identifier in the RPC interface. e.g. filter and subscription identifier.

()

Source from the content-addressed store, hash-verified

203// NewID generates a identifier that can be used as an identifier in the RPC interface.
204// e.g. filter and subscription identifier.
205func NewID() ID {
206 subscriptionIDGenMu.Lock()
207 defer subscriptionIDGenMu.Unlock()
208
209 id := make([]byte, 16)
210 for i := 0; i < len(id); i += 7 {
211 val := subscriptionIDGen.Int63()
212 for j := 0; i+j < len(id) && j < 7; j++ {
213 id[i+j] = byte(val)
214 val >>= 8
215 }
216 }
217
218 rpcId := hex.EncodeToString(id)
219 // rpc ID's are RPC quantities, no leading zero's and 0 is 0x0
220 rpcId = strings.TrimLeft(rpcId, "0")
221 if rpcId == "" {
222 rpcId = "0"
223 }
224
225 return ID("0x" + rpcId)
226}

Callers 2

TestNewIDFunction · 0.85
CreateSubscriptionMethod · 0.85

Calls 3

IDTypeAlias · 0.85
LockMethod · 0.80
UnlockMethod · 0.80

Tested by 1

TestNewIDFunction · 0.68