UpdatePermission sends UpdatePermission transaction to chain.
(targetUser proto.AccountAddress, targetChain proto.AccountAddress, perm *types.UserPermission)
| 353 | |
| 354 | // UpdatePermission sends UpdatePermission transaction to chain. |
| 355 | func UpdatePermission(targetUser proto.AccountAddress, |
| 356 | targetChain proto.AccountAddress, perm *types.UserPermission) (txHash hash.Hash, err error) { |
| 357 | if atomic.LoadUint32(&driverInitialized) == 0 { |
| 358 | err = ErrNotInitialized |
| 359 | return |
| 360 | } |
| 361 | |
| 362 | var ( |
| 363 | pubKey *asymmetric.PublicKey |
| 364 | privKey *asymmetric.PrivateKey |
| 365 | addr proto.AccountAddress |
| 366 | nonce interfaces.AccountNonce |
| 367 | ) |
| 368 | if pubKey, err = kms.GetLocalPublicKey(); err != nil { |
| 369 | return |
| 370 | } |
| 371 | if privKey, err = kms.GetLocalPrivateKey(); err != nil { |
| 372 | return |
| 373 | } |
| 374 | if addr, err = crypto.PubKeyHash(pubKey); err != nil { |
| 375 | return |
| 376 | } |
| 377 | |
| 378 | nonce, err = getNonce(addr) |
| 379 | if err != nil { |
| 380 | return |
| 381 | } |
| 382 | |
| 383 | up := types.NewUpdatePermission(&types.UpdatePermissionHeader{ |
| 384 | TargetSQLChain: targetChain, |
| 385 | TargetUser: targetUser, |
| 386 | Permission: perm, |
| 387 | Nonce: nonce, |
| 388 | }) |
| 389 | err = up.Sign(privKey) |
| 390 | if err != nil { |
| 391 | log.WithError(err).Warning("sign failed") |
| 392 | return |
| 393 | } |
| 394 | addTxReq := new(types.AddTxReq) |
| 395 | addTxResp := new(types.AddTxResp) |
| 396 | addTxReq.Tx = up |
| 397 | err = requestBP(route.MCCAddTx, addTxReq, addTxResp) |
| 398 | if err != nil { |
| 399 | log.WithError(err).Warning("send tx failed") |
| 400 | return |
| 401 | } |
| 402 | |
| 403 | txHash = up.Hash() |
| 404 | return |
| 405 | } |
| 406 | |
| 407 | // TransferToken send Transfer transaction to chain. |
| 408 | func TransferToken(targetUser proto.AccountAddress, amount uint64, tokenType types.TokenType) ( |