Skip to content

Commit

Permalink
Add validation of signatures definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Mar 4, 2017
1 parent 3866d31 commit 48c5a03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 17 additions & 7 deletions core/validation/transaction_validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <algorithm>
#include <infra/protobuf/api.pb.h>
#include <crypto/signature.hpp>
#include "transaction_validator.hpp"

namespace transaction_validator {

using Api::ConsensusEvent;
using Api::Transaction;

template<>
bool isValid<ConsensusEvent>(
const std::unique_ptr<ConsensusEvent>& tx
){
// Write domain logic
return true;
bool signaturesAreValid<ConsensusEvent>(const std::unique_ptr<ConsensusEvent>& tx){
return tx->eventsignatures().end() != std::find_if(tx->eventsignatures().begin(), tx->eventsignatures().end(),
[&tx](const auto &sig) {
return !signature::verify(sig.signature(), tx->transaction().hash(), sig.publickey());
});
}

template<>
bool signaturesAreValid<Transaction>(const std::unique_ptr<Transaction>& tx){
return tx->txsignatures().end() != std::find_if(tx->txsignatures().begin(), tx->txsignatures().end(),
[&tx](const auto &sig) {
return !signature::verify(sig.signature(), tx->hash(), sig.publickey());
});
}


};
};
2 changes: 0 additions & 2 deletions core/validation/transaction_validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ limitations under the License.

namespace transaction_validator {

using Api::ConsensusEvent;

template<typename T>
bool isValid(const std::unique_ptr<T>& tx);

Expand Down

0 comments on commit 48c5a03

Please sign in to comment.