MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TransferToken

Function TransferToken

client/driver.go:408–460  ·  view source on GitHub ↗

TransferToken send Transfer transaction to chain.

(targetUser proto.AccountAddress, amount uint64, tokenType types.TokenType)

Source from the content-addressed store, hash-verified

406
407// TransferToken send Transfer transaction to chain.
408func TransferToken(targetUser proto.AccountAddress, amount uint64, tokenType types.TokenType) (
409 txHash hash.Hash, err error,
410) {
411 if atomic.LoadUint32(&driverInitialized) == 0 {
412 err = ErrNotInitialized
413 return
414 }
415
416 var (
417 pubKey *asymmetric.PublicKey
418 privKey *asymmetric.PrivateKey
419 addr proto.AccountAddress
420 nonce interfaces.AccountNonce
421 )
422 if pubKey, err = kms.GetLocalPublicKey(); err != nil {
423 return
424 }
425 if privKey, err = kms.GetLocalPrivateKey(); err != nil {
426 return
427 }
428 if addr, err = crypto.PubKeyHash(pubKey); err != nil {
429 return
430 }
431
432 nonce, err = getNonce(addr)
433 if err != nil {
434 return
435 }
436
437 tran := types.NewTransfer(&types.TransferHeader{
438 Sender: addr,
439 Receiver: targetUser,
440 Amount: amount,
441 TokenType: tokenType,
442 Nonce: nonce,
443 })
444 err = tran.Sign(privKey)
445 if err != nil {
446 log.WithError(err).Warning("sign failed")
447 return
448 }
449 addTxReq := new(types.AddTxReq)
450 addTxResp := new(types.AddTxResp)
451 addTxReq.Tx = tran
452 err = requestBP(route.MCCAddTx, addTxReq, addTxResp)
453 if err != nil {
454 log.WithError(err).Warning("send tx failed")
455 return
456 }
457
458 txHash = tran.Hash()
459 return
460}
461
462// WaitTxConfirmation waits for the transaction with target hash txHash to be confirmed. It also
463// returns if any error occurs or a final state is returned from BP.

Callers 3

runTransferFunction · 0.92
ApplyTokenTaskFunction · 0.92
TestTransferTokenFunction · 0.85

Calls 10

SignMethod · 0.95
GetLocalPublicKeyFunction · 0.92
GetLocalPrivateKeyFunction · 0.92
PubKeyHashFunction · 0.92
NewTransferFunction · 0.92
WithErrorFunction · 0.92
getNonceFunction · 0.85
requestBPFunction · 0.85
WarningMethod · 0.80
HashMethod · 0.65

Tested by 1

TestTransferTokenFunction · 0.68