Skip to content

Commit

Permalink
noto: simplify delegate mapping
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Sep 16, 2024
1 parent 86a1a64 commit e4b52cb
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions solidity/contracts/domains/noto/Noto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {INoto} from "../interfaces/INoto.sol";
/// be using any model programmable via EVM (not just C-UTXO)
///
contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto {
mapping(bytes32 => bool) private _unspent;
mapping(bytes32 => ApprovalRecord) private _approvals;
address _notary;
mapping(bytes32 => bool) private _unspent;
mapping(bytes32 => address) private _approvals;

error NotoInvalidNotary(address signer, address notary);
error NotoInvalidInput(bytes32 id);
Expand All @@ -49,10 +49,6 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto {
bytes32 private constant TRANSFER_TYPEHASH =
keccak256("Transfer(bytes32[] inputs,bytes32[] outputs,bytes data)");

struct ApprovalRecord {
address delegate;
}

function requireNotary(address addr) internal view {
if (addr != _notary) {
revert NotoNotNotary(addr);
Expand Down Expand Up @@ -121,7 +117,7 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto {
function getTransferApproval(
bytes32 txhash
) public view returns (address delegate) {
return _approvals[txhash].delegate;
return _approvals[txhash];
}

/**
Expand Down Expand Up @@ -198,7 +194,7 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto {
bytes32 txhash,
bytes calldata signature
) internal {
_approvals[txhash].delegate = delegate;
_approvals[txhash] = delegate;
emit UTXOApproved(delegate, txhash, signature);
}

Expand All @@ -218,12 +214,8 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto {
bytes calldata data
) public {
bytes32 txhash = _buildTXHash(inputs, outputs, data);
if (_approvals[txhash].delegate != msg.sender) {
revert NotoInvalidDelegate(
txhash,
_approvals[txhash].delegate,
msg.sender
);
if (_approvals[txhash] != msg.sender) {
revert NotoInvalidDelegate(txhash, _approvals[txhash], msg.sender);
}

_transfer(inputs, outputs, signature, data);
Expand Down

0 comments on commit e4b52cb

Please sign in to comment.