-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ajin.liu
committed
Jul 19, 2024
1 parent
74f69d0
commit 9558701
Showing
9 changed files
with
276 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 2 | ||
manifest_digest = "B5DFE43F250BB938EE9828C717632F7F086718850E759E21E47F987E609B9DFF" | ||
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" | ||
dependencies = [ | ||
{ name = "Sui" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "MoveStdlib" | ||
source = { git = "https://gitee.com/mystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
name = "Sui" | ||
source = { git = "https://gitee.com/mystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ name = "MoveStdlib" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.29.0" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x045eff3eaf7a574b1607fb8fd930adfa634e06c2e9cffe28b8963ddb499dedde" | ||
latest-published-id = "0x045eff3eaf7a574b1607fb8fd930adfa634e06c2e9cffe28b8963ddb499dedde" | ||
published-version = "1" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "ajin8898_coin" | ||
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move | ||
# license = "" # e.g., "MIT", "GPL", "Apache 2.0" | ||
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"] | ||
|
||
[dependencies] | ||
Sui = { git = "https://gitee.com/mystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" } | ||
|
||
# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. | ||
# Revision can be a branch, a tag, and a commit hash. | ||
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } | ||
|
||
# For local dependencies use `local = path`. Path is relative to the package root | ||
# Local = { local = "../path/to" } | ||
|
||
# To resolve a version conflict and force a specific version for dependency | ||
# override use `override = true` | ||
# Override = { local = "../conflicting/version", override = true } | ||
|
||
[addresses] | ||
ajin8898_coin = "0x0" | ||
|
||
# Named addresses will be accessible in Move as `@name`. They're also exported: | ||
# for example, `std = "0x1"` is exported by the Standard Library. | ||
# alice = "0xA11CE" | ||
|
||
[dev-dependencies] | ||
# The dev-dependencies section allows overriding dependencies for `--test` and | ||
# `--dev` modes. You can introduce test-only dependencies here. | ||
# Local = { local = "../path/to/dev-build" } | ||
|
||
[dev-addresses] | ||
# The dev-addresses section allows overwriting named addresses for the `--test` | ||
# and `--dev` modes. | ||
# alice = "0xB0B" | ||
|
35 changes: 35 additions & 0 deletions
35
mover/ajin8898/code/task2/ajin8898_coin/sources/ajin8898_coin.move
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// Module: ajin8898_coin | ||
module ajin8898_coin::ajin8898_coin { | ||
|
||
use sui::coin::{Self, Coin, TreasuryCap}; | ||
|
||
public struct AJIN8898_COIN has drop {} | ||
|
||
fun init(witness: AJIN8898_COIN, ctx: &mut TxContext) { | ||
let (treasury, metadata) = coin::create_currency( | ||
witness, | ||
6, // decimals | ||
b"ajin8898 COIN", // symbol | ||
b"ajin8898 COIN", // name | ||
b"Amazing Coin", // description | ||
option:: none(), // icon url | ||
ctx | ||
); | ||
transfer::public_freeze_object(metadata); | ||
transfer::public_transfer(treasury, tx_context::sender(ctx)); | ||
} | ||
|
||
public entry fun mint( | ||
treasury_cap: &mut TreasuryCap<AJIN8898_COIN>, | ||
amount: u64, | ||
recipient: address, | ||
ctx: &mut TxContext | ||
) { | ||
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); | ||
} | ||
|
||
public entry fun burn(treasury_cap: &mut TreasuryCap<AJIN8898_COIN>, coin: Coin<AJIN8898_COIN>) { | ||
coin::burn(treasury_cap, coin); | ||
} | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
mover/ajin8898/code/task2/ajin8898_coin/tests/ajin8898_coin_tests.move
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
#[test_only] | ||
module ajin8898_coin::ajin8898_coin_tests { | ||
// uncomment this line to import the module | ||
// use ajin8898_coin::ajin8898_coin; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_ajin8898_coin() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::ajin8898_coin::ajin8898_coin_tests::ENotImplemented)] | ||
fun test_ajin8898_coin_fail() { | ||
abort ENotImplemented | ||
} | ||
} | ||
*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 2 | ||
manifest_digest = "D51D07EF3A9EF45AAB95AC659D5581EA6C3F8DB9A6F61BA710178325CEBD1679" | ||
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" | ||
dependencies = [ | ||
{ name = "Sui" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "MoveStdlib" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
name = "Sui" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ name = "MoveStdlib" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.29.0" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x1e7aed8b04e58aabe6b7082875d6e3055c3f61d0239a26622dfb363c75fab2e4" | ||
latest-published-id = "0x1e7aed8b04e58aabe6b7082875d6e3055c3f61d0239a26622dfb363c75fab2e4" | ||
published-version = "1" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "ajin8898_faucet" | ||
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move | ||
# license = "" # e.g., "MIT", "GPL", "Apache 2.0" | ||
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"] | ||
|
||
[dependencies] | ||
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" } | ||
|
||
# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. | ||
# Revision can be a branch, a tag, and a commit hash. | ||
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } | ||
|
||
# For local dependencies use `local = path`. Path is relative to the package root | ||
# Local = { local = "../path/to" } | ||
|
||
# To resolve a version conflict and force a specific version for dependency | ||
# override use `override = true` | ||
# Override = { local = "../conflicting/version", override = true } | ||
|
||
[addresses] | ||
ajin8898_faucet = "0x0" | ||
|
||
# Named addresses will be accessible in Move as `@name`. They're also exported: | ||
# for example, `std = "0x1"` is exported by the Standard Library. | ||
# alice = "0xA11CE" | ||
|
||
[dev-dependencies] | ||
# The dev-dependencies section allows overriding dependencies for `--test` and | ||
# `--dev` modes. You can introduce test-only dependencies here. | ||
# Local = { local = "../path/to/dev-build" } | ||
|
||
[dev-addresses] | ||
# The dev-addresses section allows overwriting named addresses for the `--test` | ||
# and `--dev` modes. | ||
# alice = "0xB0B" | ||
|
56 changes: 56 additions & 0 deletions
56
mover/ajin8898/code/task2/ajin8898_faucet/sources/ajin8898_faucet.move
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module ajin8898_faucet::ajin8898_faucet { | ||
use sui::balance::{Balance}; | ||
use sui::balance; | ||
use sui::coin::{Self, TreasuryCap}; | ||
public struct AJIN8898_FAUCET has drop {} | ||
public struct PublicWallet has key { | ||
id: UID, | ||
coin: Balance<AJIN8898_FAUCET>, | ||
faucet_amount: u64, | ||
} | ||
const AMOUNT: u64 = 10^12; | ||
const EFaucetDry: u64 = 1; | ||
#[allow(lint(share_owned))] | ||
fun init(witness: AJIN8898_FAUCET, ctx: &mut TxContext) { | ||
let (treasury_cap, metadata) = coin::create_currency<AJIN8898_FAUCET>( | ||
witness, | ||
10, | ||
b"ajin8898 Faucet", | ||
b"ajin8898 Faucet coin", | ||
b"Get some free", | ||
option::none(), | ||
ctx); | ||
transfer::public_freeze_object(metadata); | ||
transfer::public_transfer(treasury_cap, tx_context::sender(ctx)); | ||
let wallet = PublicWallet { | ||
id: object::new(ctx), | ||
coin: balance::zero(), | ||
faucet_amount: AMOUNT, | ||
}; | ||
transfer::share_object(wallet); | ||
} | ||
public entry fun mint_faucet( | ||
treasury_cap: &mut TreasuryCap<AJIN8898_FAUCET>, | ||
amount: u64, | ||
wallet: &mut PublicWallet, | ||
ctx: &mut TxContext) { | ||
let coins = coin::mint(treasury_cap, amount, ctx); | ||
balance::join(&mut wallet.coin, coin::into_balance(coins)); | ||
} | ||
public entry fun get_faucet(wallet: &mut PublicWallet, ctx: &mut TxContext) { | ||
let balance_amount = balance::value(&wallet.coin); | ||
assert!(balance_amount >= wallet.faucet_amount, EFaucetDry); | ||
let mint_balance = balance::split(&mut wallet.coin, wallet.faucet_amount); | ||
let faucet_coin = coin::from_balance(mint_balance, ctx); | ||
transfer::public_transfer(faucet_coin, tx_context::sender(ctx)); | ||
} | ||
} | ||
|
||
// 切换地址 | ||
// sui client switch --address 0x74a3ba8cd6f6331093c7bbc36d4bb805ff90b9eb3fe128d402fc03e13cc9ae87 | ||
|
||
// address1: sui client call --function mint_faucet --package 0x35492b3e019b3f5cec1e00190de1e751013114214b4e94dce2e4193215ef2d82 --module ajin8898_faucet --args 0x7aaf7fb6d11b56ba1d3be789347122044bc352c7a3928ca67ea226fecb27929a 100000000 0xe7d6073ff1188cc6159aff80580a61d53528a8171c949b6a3695fdc91f834f84 --gas-budget 50000000 | ||
// Transaction Effects > Created Objects > Owner: Shared > ID: 0xe7d6073ff1188cc6159aff80580a61d53528a8171c949b6a3695fdc91f834f84 | ||
// address2: sui client call --function mint_faucet --package 0x1e7aed8b04e58aabe6b7082875d6e3055c3f61d0239a26622dfb363c75fab2e4 --module ajin8898_faucet --args 0x8db67ea7888ff9ad60716fd5ac409734c15c9fdbd2e16aaa3b9ddd06ac1d06ef 100000000 0x9def82b646bc4c2e2fcdad7fcd6704a5d5267118bb07539f10f9c151ddc3e37b --gas-budget 50000000 | ||
|
||
// 0x9def82b646bc4c2e2fcdad7fcd6704a5d5267118bb07539f10f9c151ddc3e37b |
19 changes: 19 additions & 0 deletions
19
mover/ajin8898/code/task2/ajin8898_faucet/tests/ajin8898_faucet_tests.move
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
#[test_only] | ||
module ajin8898_faucet::ajin8898_faucet_tests { | ||
// uncomment this line to import the module | ||
// use ajin8898_faucet::ajin8898_faucet; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_ajin8898_faucet() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::ajin8898_faucet::ajin8898_faucet_tests::ENotImplemented)] | ||
fun test_ajin8898_faucet_fail() { | ||
abort ENotImplemented | ||
} | ||
} | ||
*/ |
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