From ad0736badaadecbeb89d87d9886c7c828c286bee Mon Sep 17 00:00:00 2001 From: Tina Lee <92625071+Learning-N-Running@users.noreply.github.com> Date: Thu, 23 May 2024 21:22:05 +0900 Subject: [PATCH 1/2] Feat: done all missions --- projects/coding-assignment/src/Home.tsx | 11 +++++++++-- projects/coding-assignment/src/methods.ts | 17 +++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/projects/coding-assignment/src/Home.tsx b/projects/coding-assignment/src/Home.tsx index 5c77384..858b3ea 100644 --- a/projects/coding-assignment/src/Home.tsx +++ b/projects/coding-assignment/src/Home.tsx @@ -6,9 +6,9 @@ import algosdk from 'algosdk' import React, { useEffect, useState } from 'react' import ConnectWallet from './components/ConnectWallet' import MethodCall from './components/MethodCall' +import { DigitalMarketplaceClient } from './contracts/DigitalMarketplace' import * as methods from './methods' import { getAlgodConfigFromViteEnvironment } from './utils/network/getAlgoClientConfigs' - interface HomeProps {} const Home: React.FC = () => { @@ -83,7 +83,14 @@ const Home: React.FC = () => { */ // 문제 1 시작 - const dmClient = '여기에 코드 작성' + const dmClient = new DigitalMarketplaceClient( + { + resolveBy: 'id', + id: appId, + sender: { addr: activeAddress!, signer }, + }, + algorand.client.algod, + ) // 문제 1 끝 const toggleWalletModal = () => { diff --git a/projects/coding-assignment/src/methods.ts b/projects/coding-assignment/src/methods.ts index b62e745..71cf9f9 100644 --- a/projects/coding-assignment/src/methods.ts +++ b/projects/coding-assignment/src/methods.ts @@ -60,7 +60,8 @@ export function create( */ // 문제 2 시작 - const createResult = '여기에 코드 작성' + const createResult = await dmClient.create.bare() + // 문제 2 끝 /* @@ -85,10 +86,14 @@ export function create( sender, receiver: createResult.appAddress, amount: algokit.algos(0.1 + 0.1), - extraFee: '여기에 코드 작성', + extraFee: algokit.algos(0.001), }) - ;('여기에 bootstrap 메서드 호출 코드 작성') + await dmClient.bootstrap({ + asset: assetId, + unitaryPrice: unitaryPrice, + mbrPay: mbrTxn, + }) // 문제 3 끝 await algorand.send.assetTransfer({ @@ -130,10 +135,10 @@ export function buy( sender, receiver: appAddress, amount: algokit.microAlgos(Number(quantity * unitaryPrice)), - extraFee: '여기에 코드 작성', + extraFee: algokit.algos(0.001), }) - ;('여기에 buy 메서드 호출 코드 작성') + await dmClient.buy({ buyerTxn: buyerTxn, quantity: quantity }) // 문제 4 끝 const state = await dmClient.getGlobalState() @@ -173,7 +178,7 @@ export function deleteApp(dmClient: DigitalMarketplaceClient, setAppId: (id: num */ // 문제 5 시작 - '여기에 코드 작성' + await dmClient.delete.withdrawAndDelete({}, { sendParams: { fee: algokit.transactionFees(3) } }) // 문제 5 끝 setAppId(0) } From 436d321cb8bcb00f8cfd4e38e49c52faf1509199 Mon Sep 17 00:00:00 2001 From: Tina Lee <92625071+Learning-N-Running@users.noreply.github.com> Date: Thu, 23 May 2024 21:23:33 +0900 Subject: [PATCH 2/2] Feat: add annotation --- .../smart_contracts/personal_bank/contract.py | 2 +- .../smart_contracts/personal_bank/deploy-config.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/projects/blockchain-valley-session-4/smart_contracts/personal_bank/contract.py b/projects/blockchain-valley-session-4/smart_contracts/personal_bank/contract.py index 9f164fb..433eb8c 100644 --- a/projects/blockchain-valley-session-4/smart_contracts/personal_bank/contract.py +++ b/projects/blockchain-valley-session-4/smart_contracts/personal_bank/contract.py @@ -43,7 +43,7 @@ def withdraw(self) -> UInt64: receiver=Txn.sender, sender=Global.current_application_address, amount=userBalance, - fee=0, + fee=0, #여기서는 0으로 하고 호출자가 낼 수 있게 로직을 설정해주기. ).submit() return userBalance diff --git a/projects/blockchain-valley-session-4/smart_contracts/personal_bank/deploy-config.ts b/projects/blockchain-valley-session-4/smart_contracts/personal_bank/deploy-config.ts index feaa45a..0ffd927 100644 --- a/projects/blockchain-valley-session-4/smart_contracts/personal_bank/deploy-config.ts +++ b/projects/blockchain-valley-session-4/smart_contracts/personal_bank/deploy-config.ts @@ -12,7 +12,7 @@ export async function deploy() { const algorand = algokit.AlgorandClient.defaultLocalNet() // 랜덤 계정 생성 후 자금 지급 - const deployer = await algorand.account.random() + const deployer = await algorand.account.random() //은행 계정 const user = await algorand.account.random() const user2 = await algorand.account.random() const accounts = [deployer, user, user2] @@ -32,7 +32,7 @@ export async function deploy() { //1. Deployer의 Personal Bank 앱 클라이언트 생성 const appClient = new PersonalBankClient( { - resolveBy: 'creatorAndName', + resolveBy: 'creatorAndName', //배포자의 계정 주소랑 이름으로 찾음. findExistingUsing: indexer, sender: deployer, creatorAddress: deployer.addr, @@ -96,8 +96,9 @@ export async function deploy() { 첫번째 전달값으로 넣어주면 자동으로 어토믹 그룹으로 묶어줍니다. */ + // compose를 하면 줄줄이 소시지로 연결 가능 await appClient.compose().optIn.optInToApp({}).deposit({ ptxn: depositTxn }).execute({ suppressLog: true }) - + // suppress log = True를 하면 로그가 뜨는 걸 막을 수 있음. console.log(`=== ${userName} 출금 전 ===`) let appInfo = await algorand.account.getInformation(app.appAddress) @@ -118,7 +119,7 @@ export async function deploy() { userName: string, user: TransactionSignerAccount, ): Promise { - await appClient.closeOut.withdraw({}, { sendParams: { fee: algokit.transactionFees(2) } }) + await appClient.closeOut.withdraw({}, { sendParams: { fee: algokit.transactionFees(2) } }) //여기서 fee 설정 console.log(`=== ${userName} 출금 후 ===`) const appInfo = await algorand.account.getInformation(app.appAddress)