Rinkeby 智能合约

问题描述

希望为 CTF 创造一个挑战,在那里我为用户提供了一份智能合约,要求最低成本为 20 以太币。一旦付款被接受,他就可以返回标志。下面的代码有效,并根据 remix 中的帐户检查余额,但是如果付款正确,我怎样才能让它返回标志? 任何帮助和指示将不胜感激。

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

contract payment_for_art {
    function invest() external payable {
        if(msg.value < 20 ether) {
            revert();
        }
    }
    function balance_of() external view returns(uint) {
        return address(this).balance;
    }
}

问候

K

解决方法

您可以创建一个 //this is my controller async getTasksCount (req,res) { try { let resultall = {}; const strDate = moment().startOf('day').utc().toDate(); const endDate = moment().endOf('day').utc().toDate() let todayTask = await tasksRepo.getToDayTaskCount({"isDeleted" : false,"isScheduled": true,"isCompleted": false,startDate: { $ne: null },$expr: { $or: [ { $gte: ['strDate',moment().startOf('day').utc().toDate()] },{ $lte: ['endDate',moment().endOf('day').utc().toDate()] } ] } }); console.log("x1"+strDate) console.log("x2"+endDate) console.log("xx"+ todayTask.length) } //this is the query written for expression match and to get projection of data with start and end date we have some kind of pattern we make repo called file in project in that we write queries or else normally this method would be in controller getToDayTaskCount: async (params) => { try { let aggregate = await TasksModel.aggregate([ { $project:{ _id: '$_id',title: '$title',description: '$description',isCompleted: '$isCompleted',isScheduled: '$isScheduled',status: '$status',strDate: { $dateToString: { format: "%Y-%m-%d",date: "$start" } },endDate: { $dateToString: { format: "%Y-%m-%d",date: "$end" } },isDeleted: '$isDeleted',// daysCount: { // $round: { // $divide: [ // { // $subtract: [ // "$end",// "$start" // ] // },// 86400000 // ] // } // } },},{$match: params},]); return aggregate; } catch (e) { return e; } },//this is my model if needed const TasksSchema = new Schema({ title: { type: String,default: '' },workorder_id: { type: Schema.Types.ObjectId,ref: 'Workorders',default: null },manager: { type: Schema.Types.ObjectId,ref: 'User',technicians: [{ type: Schema.Types.ObjectId,default: null }],description: { type: String,start: { type: Date,end: { type: Date,timezone: { type: String,isCompleted: { type: Boolean,default: false,enum: [true,false] },price: { type: Schema.Types.Double,default: 0.00 },status: { type: String,default: 'New',enum: status },isDeleted: { type: Boolean,{ timestamps: true,versionKey: false }); 属性来标记付款是否已完成。

bool

由于它具有 contract payment_for_art { // default value is `false`,don't need to explicitly state it bool public isPaid; function invest() external payable { // to prevent multiple payments // reverts if the condition is not met require(isPaid == false); if(msg.value < 20 ether) { revert(); } isPaid = true; // flag that the payment has been done } // ... rest of your code } 修饰符,任何其他合约或链下应用程序都可以读取其值(但不能重写它)。如果您不希望从合同外部访问该值,您可以删除修饰符。