Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gracecampo #2050

Merged
merged 8 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mover/gracecampo/co-learn-2411/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
- [√] 第一周:![学习记录截图](images/直播答疑/共学营开营仪式.jpg):参与共学营开营仪式并积极互动
- [√] 第一周:![学习记录截图](images/直播答疑/第一周直播答疑.jpg):参与第一周直播答疑并积极互动
- [√] 第二周:![学习记录截图](images/直播答疑/第二周直播答疑.png):参与第二周直播答疑并积极互动
- [√] 第二周:![学习记录截图](images/直播答疑/共学营分享会.png) :分享并参与共学营讨论并积极互动
- [√] 第三周:![学习记录截图](images/直播答疑/第三周直播答疑.png):参与第一周直播答疑并积极互动
- [] 第四周:![学习记录截图](./images/你的图片地址)

Expand All @@ -36,6 +35,8 @@
- [√] 第九篇笔记[move入门之基础语法(一)](https://learnblockchain.cn/article/9966)
- [√] 第十篇笔记[MOVE共学营TASK5教程](https://learnblockchain.cn/article/10035)
- [√] 第十一篇笔记[move入门之泛型](https://learnblockchain.cn/article/10036)
- [√] 第十二篇笔记[move入门之集合(一)](https://learnblockchain.cn/article/10090)
- [√] 第十三篇笔记[move入门之集合(二)](https://learnblockchain.cn/article/10091)
## 对外输出学习笔记

- [√] 第一篇笔记[Git入门到精通](https://blog.csdn.net/jinpeng741143592/article/details/143261589?spm=1001.2014.3001.5502)
Expand All @@ -51,7 +52,9 @@
- [√] 第十一篇笔记[MOVE共学营TASK4教程](https://learnblockchain.cn/article/9959)
- [√] 第十二篇笔记[move入门之基础语法(一)](https://learnblockchain.cn/article/9966)
- [√] 第十三篇笔记[MOVE共学营TASK5教程](https://learnblockchain.cn/article/10035)
- [√] 第十三篇笔记[move入门之泛型](https://learnblockchain.cn/article/10036)
- [√] 第十四篇笔记[move入门之泛型](https://learnblockchain.cn/article/10036)
- [√] 第十五篇笔记[move入门之集合(一)](https://learnblockchain.cn/article/10090)
- [√] 第十六篇笔记[move入门之集合(二)](https://learnblockchain.cn/article/10091)
## 在HOH社区公众号发布自己的技术文章

- [] 第一篇笔记【公众号文章链接】
Expand All @@ -61,7 +64,7 @@

## 直播分享学习技巧/工具推荐

- [] 会议截图:![会议记录截图](./images/你的图片地址)
- [] 会议截图:![会议记录截图](images/直播答疑/共学营分享会.png)

## 提交项目

Expand Down
60 changes: 60 additions & 0 deletions mover/gracecampo/code/task6/SdkPtbNavi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useState } from 'react';
import {useCurrentAccount, useSignAndExecuteTransaction} from '@mysten/dapp-kit';
import { Transaction } from '@mysten/sui/transactions';
import {pool, Sui, wUSDC} from "navi-sdk/dist/address";
import {Pool, PoolConfig} from "navi-sdk/dist/types";
import {borrowCoin, depositCoin} from "navi-sdk/dist/libs/PTB";

export function SdkPtbNavi() {
const {mutate: handleSignAndExecuteTransaction } = useSignAndExecuteTransaction();
const [isLoading, setLoading] = useState(false);
//获取钱包链接用户
const account = useCurrentAccount();
const executeTransaction = async () => {
const transaction = new Transaction();
// 设置交易的详细信息
transaction.setSender(account!.address);
const now = new Date();
const hour= now.getHours();
const day = now.getDate();
const month = now.getMonth() + 1; // 月份是从0开始的,所以需要+1
// 将时间格式化为 0.[月][天][小时] 的形式,如 "0.421" 代表4月21日15时
const borrow_amount = parseFloat(`0.${month.toString().padStart(2, '0')}${day.toString().padStart(2, '0')}${hour.toString().padStart(2, '0')}`) * (10 ** wUSDC.decimal);
setLoading(true);
try {
const suiPool: PoolConfig = pool[Sui.symbol as keyof Pool];
const [suiCoin] = transaction.splitCoins(transaction.gas, [1_000_000_000]); // 1 SUI = 10^9 MIST
await depositCoin(transaction, suiPool, suiCoin, 1_000_000_000);
console.log('deposit_amount count', suiCoin.NestedResult);
console.log('borrow count', borrow_amount);
const wusdcPool: PoolConfig = pool[wUSDC.symbol as keyof Pool];
const [toBorrowCoin] = await borrowCoin(transaction, wusdcPool, borrow_amount);
await depositCoin(transaction, wusdcPool,toBorrowCoin, borrow_amount);
console.log('signAndExecuteTransaction');
//const result = await handleSignAndExecuteTransaction(transaction, 'sdk-ptb-navi', setLoading);
// console.log('Transaction executed successfully',result);
handleSignAndExecuteTransaction(
{transaction: transaction,}, {
onError: (err) => {
console.log('Transaction failed', err);
},
onSuccess: (result) => {
console.log('signAndExecuteTransaction',result);
},
})
setLoading(true);
} catch (error) {
console.error('Transaction failed', error);
} finally {
setLoading(false);
}
};

return (
<div>
<button onClick={executeTransaction} disabled={isLoading}>
{isLoading ? 'Executing...' : 'Execute Transaction'}
</button>
</div>
);
}
80 changes: 80 additions & 0 deletions mover/gracecampo/code/task7/check_in.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module check_in::check_in {
use std::ascii::{String, string};
use std::bcs;
use std::hash::sha3_256;
use sui::event;
use sui::object;
use sui::random;
use sui::random::Random;
use sui::transfer::share_object;
use sui::tx_context::{Self, TxContext};
#[test_only]
use std::ascii::as_bytes;

const ESTRING: u64 = 0;

public struct Flag has copy, drop {
sender: address,
flag: bool,
ture_num: u64,
github_id: String
}

public struct FlagString has key {
id: UID,
str: String,
ture_num: u64
}

fun init(ctx: &mut TxContext) {
let flag_str = FlagString {
id: object::new(ctx),
str: string(b"LetsMoveCTF"),
ture_num: 0
};
share_object(flag_str);
}


entry fun get_flag(
flag: vector<u8>,
github_id: String,
flag_str: &mut FlagString,
rand: &Random,
ctx: &mut TxContext
) {
let mut bcs_flag = bcs::to_bytes(&flag_str.str);
vector::append<u8>(&mut bcs_flag, *github_id.as_bytes());

assert!(flag == sha3_256(bcs_flag), ESTRING);

flag_str.str = getRandomString(rand, ctx);

flag_str.ture_num = flag_str.ture_num + 1;

event::emit(Flag {
sender: tx_context::sender(ctx),
flag: true,
ture_num: flag_str.ture_num,
github_id
});
}


fun getRandomString(rand: &Random, ctx: &mut TxContext): String {
let mut gen = random::new_generator(rand, ctx);

let mut str_len = random::generate_u8_in_range(&mut gen, 4, 30);

let mut rand: vector<u8> = b"";
while (str_len != 0) {
let rand_num = random::generate_u8_in_range(&mut gen, 34, 126);
vector::push_back(&mut rand, rand_num);
str_len = str_len - 1;
};

string(rand)
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
`dApp Kit` 是一组 React 组件、hooks 和工具,旨在帮助您在 Sui 区块链上构建去中心化应用程序(dApps)。它简化了连接钱包、签署交易和从 RPC 节点获取数据等任务。

### 主要功能:
- **查询 Hooks**:获取 dApp 所需的数据。
- **自动钱包状态管理**:无缝管理钱包连接。
- **支持所有 Sui 钱包**:兼容多种 Sui 钱包。
- **预构建的 React 组件**:使用现成组件加速开发。
- **可定制的 Hooks**:使用低级别的 hooks 创建自定义组件。

### 前置环境:
1. nodejs
2. npm

### 安装:
要开始使用 dApp Kit,您需要安装必要的包:

使用npm安装
```bash
npm install --save @mysten/dapp-kit @mysten/sui.js @tanstack/react-query
```
使用yarn安装
```bash
yarn add @mysten/dapp-kit @mysten/sui @tanstack/react-query
```



### 设置 Providers:
使用所需的 providers 包装您的应用,以使用 hooks 和组件:

```javascript
import '@mysten/dapp-kit/dist/index.css';
import { SuiClientProvider, WalletProvider } from '@mysten/dapp-kit';
import { getFullnodeUrl } from '@mysten/sui.js/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const queryClient = new QueryClient();
const networks = {
localnet: { url: getFullnodeUrl('localnet') },
devnet: { url: getFullnodeUrl('devnet') },
testnet: { url: getFullnodeUrl('testnet') },
mainnet: { url: getFullnodeUrl('mainnet') },
};

ReactDOM.createRoot(document.getElementById('root')!).render(
<QueryClientProvider client={queryClient}>
<SuiClientProvider networks={networks} defaultNetwork="devnet">
<WalletProvider>
<App />
</WalletProvider>
</SuiClientProvider>
</QueryClientProvider>,
);
```

### 连接钱包:
添加 `ConnectButton` 以使用户能够连接他们的 Sui 钱包:

```javascript
import { ConnectButton } from '@mysten/dapp-kit';

function App() {
return (
<div>
<nav>
<ConnectButton />
</nav>
<section>Hello, world</section>
</div>
);
}
```

有关更详细的信息和高级功能,您可以查看 [dApp Kit 文档](https://sdk.mystenlabs.com/dapp-kit)。
Loading