readCallers

签名

enum CallerMode {
    None,
    Broadcast,
    RecurrentBroadcast,
    Prank,
    RecurrentPrank
}

function readCallers() 
external 
returns (CallerMode callerMode, address msgSender, address txOrigin);

描述

读取当前的CallerModemsg.sendertx.origin

CallerMode枚举指示是否存在活动的调用者修改以及其类型。

  • 如果存在活动的 prank:

    • 如果使用 prank 设置了 prank:
      • callerMode将等于CallerMode.Prank
    • 如果使用 startPrank 设置了 prank:
      • callerMode将等于CallerMode.RecurrentPrank
  • 如果存在活动的广播:

    • 如果使用 broadcast 设置了广播:
      • callerMode将等于CallerMode.Broadcast
    • 如果使用 startBroadcast 设置了广播:
      • callerMode将等于CallerMode.RecurrentBroadcast
  • 如果没有活动的调用者修改:

    • callerMode将等于CallerMode.None

示例

CallerMode callerMode;
address msgSender;
address txOrigin;

// Example 1
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.None);
assertEq(msgSender, defaultSenderAddress);
assertEq(txOrigin, defaultOriginAddress);

// Example 2
vm.prank(senderPrankAddress);
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.Prank);
assertEq(msgSender, senderPrankAddress);
assertEq(txOrigin, defaultOriginAddress);

// Example 3
vm.prank(senderPrankAddress, originPrankAddress);
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.Prank);
assertEq(msgSender, senderPrankAddress);
assertEq(txOrigin, originPrankAddress);

// Example 4
vm.broadcast(broadcastAddress);
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.Broadcast);
assertEq(msgSender, broadcastAddress);
assertEq(txOrigin, broadcastAddress);

另请参阅