This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers } from "hardhat"; | |
async function main() { | |
const LoveLetter = await ethers.getContractFactory("LoveLetter"); | |
const loveLetter = await LoveLetter.deploy(); | |
await loveLetter.deployed(); | |
console.log("LoveLetter deployed to:", loveLetter.address); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect } from "chai"; | |
import { Signer, utils } from "ethers"; | |
import { ethers } from "hardhat"; | |
import { LoveLetter } from "../typechain"; | |
describe("LoveLetter", () => { | |
let love: LoveLetter; | |
let sender: Signer; | |
let receiver: Signer; | |
let stranger: Signer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: Unlicense | |
pragma solidity ^0.8.0; | |
import "hardhat/console.sol"; | |
contract LoveLetter { | |
uint256 public totalLetters; | |
mapping(uint256 => address) public senders; | |
mapping(uint256 => address) public receivers; | |
struct Letter { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract LoveLetter { | |
... | |
function readMessage(uint256 id) | |
external | |
view | |
returns (string memory message) | |
{ | |
message = letters[id].message; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract LoveLetter { | |
... | |
function open(uint256 id) external returns (string memory message) { | |
require(receivers[id] == msg.sender, "Not receiver"); | |
require(!letters[id].opened, "Already opened"); | |
message = letters[id].message; | |
letters[id].opened = true; | |
uint256 amount = letters[id].etherAmount; | |
console.log("[open]", id, amount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract LoveLetter { | |
... | |
function send(address to, string memory message) | |
external | |
payable | |
returns (uint256 id) | |
{ | |
id = totalLetters; | |
senders[id] = msg.sender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: Unlicense | |
pragma solidity ^0.8.0; | |
import "hardhat/console.sol"; | |
contract LoveLetter { | |
uint256 public totalLetters; | |
mapping(uint256 => address) public senders; | |
mapping(uint256 => address) public receivers; | |
struct Letter { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: Unlicense | |
pragma solidity ^0.8.0; | |
import "hardhat/console.sol"; | |
contract LoveLetter { | |
uint256 public totalLetters; | |
mapping(uint256 => address) public senders; | |
mapping(uint256 => address) public receivers; | |
struct Letter { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function: Deposit | |
parameters: Amount, Deadline | |
code: | |
- Check if function Caller transfer asset to this contract by at least the Amount. | |
- if not, reject transaction | |
- Increase function Caller's balance by Amount. | |
- Lock this chunk of asset with the deadline. | |
function: Withdraw | |
parameters: Amount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"cstdio" | |
#include"iostream" | |
using namespace std; | |
# define N 1001 | |
int day[N][N] = {0}, minute[N][N] = {0}; | |
void print(int n) { | |
for (int i = 0; i <= n; i++) { | |
for (int j = 0; j <= n; j++) { |
NewerOlder