diff --git a/Subscription/Subscription.sol b/Subscription/Subscription.sol index 59cca71..0b45af2 100644 --- a/Subscription/Subscription.sol +++ b/Subscription/Subscription.sol @@ -33,6 +33,7 @@ contract Subscription { //who deploys the contract address public author; + uint8 public contractVersion; // the publisher may optionally deploy requirements for the subscription // so only meta transactions that match the requirements can be relayed @@ -42,6 +43,7 @@ contract Subscription { uint256 public requiredPeriodSeconds; uint256 public requiredGasPrice; + // similar to a nonce that avoids replay attacks this allows a single execution // every x seconds for a given subscription // subscriptionHash => next valid block number @@ -77,7 +79,8 @@ contract Subscription { address _tokenAddress, uint256 _tokenAmount, uint256 _periodSeconds, - uint256 _gasPrice + uint256 _gasPrice, + uint8 _version ) public { requiredToAddress=_toAddress; requiredTokenAddress=_tokenAddress; @@ -85,6 +88,7 @@ contract Subscription { requiredPeriodSeconds=_periodSeconds; requiredGasPrice=_gasPrice; author=msg.sender; + contractVersion=_version; } // this is used by external smart contracts to verify on-chain that a @@ -169,7 +173,7 @@ contract Subscription { uint256 nonce,// to allow multiple subscriptions with the same parameters bytes signature //proof the subscriber signed the meta trasaction ) - external + public view returns (bool) { @@ -242,8 +246,12 @@ contract Subscription { public returns (bool success) { + bytes32 subscriptionHash = getSubscriptionHash( + from, to, tokenAddress, tokenAmount, periodSeconds, gasPrice, nonce + ); + // make sure the subscription is valid and ready - require(isSubscriptionReady(from, to, tokenAddress, tokenAmount, periodSeconds, gasPrice, nonce, signature), "Subscription is not ready or conditions of transction are not met") + require( isSubscriptionReady(from, to, tokenAddress, tokenAmount, periodSeconds, gasPrice, nonce, signature), "Subscription is not ready or conditions of transction are not met" ); //increment the timestamp by the period so it wont be valid until then nextValidTimestamp[subscriptionHash] = block.timestamp.add(periodSeconds);