From 563052f8df1fe051c5d88aac780a5ed556669175 Mon Sep 17 00:00:00 2001 From: AETHERGY4 Date: Mon, 17 Nov 2025 04:33:48 +0000 Subject: [PATCH 1/4] Ejercicio del dia 1 --- PrimerDia/.gitignore | 4 ++++ PrimerDia/Move.toml | 36 ++++++++++++++++++++++++++++ PrimerDia/sources/primerdia.move | 15 ++++++++++++ PrimerDia/tests/primerdia_tests.move | 18 ++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 PrimerDia/.gitignore create mode 100644 PrimerDia/Move.toml create mode 100644 PrimerDia/sources/primerdia.move create mode 100644 PrimerDia/tests/primerdia_tests.move diff --git a/PrimerDia/.gitignore b/PrimerDia/.gitignore new file mode 100644 index 0000000..813de75 --- /dev/null +++ b/PrimerDia/.gitignore @@ -0,0 +1,4 @@ +build/* +traces/* +.trace +.coverage* diff --git a/PrimerDia/Move.toml b/PrimerDia/Move.toml new file mode 100644 index 0000000..e893c9a --- /dev/null +++ b/PrimerDia/Move.toml @@ -0,0 +1,36 @@ +[package] +name = "PrimerDia" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] + +# 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] +primerdia = "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" + diff --git a/PrimerDia/sources/primerdia.move b/PrimerDia/sources/primerdia.move new file mode 100644 index 0000000..406993e --- /dev/null +++ b/PrimerDia/sources/primerdia.move @@ -0,0 +1,15 @@ +module primerdia::modulo { + use std::debug::print; + + const GRAVEDAD: u8 = 10; + + fun suma() { + let numero: u8 = 10; + print(&(numero + GRAVEDAD)) + } + + #[test] + fun practica() { + suma() + } +} \ No newline at end of file diff --git a/PrimerDia/tests/primerdia_tests.move b/PrimerDia/tests/primerdia_tests.move new file mode 100644 index 0000000..4da894f --- /dev/null +++ b/PrimerDia/tests/primerdia_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module primerdia::primerdia_tests; +// uncomment this line to import the module +// use primerdia::primerdia; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_primerdia() { + // pass +} + +#[test, expected_failure(abort_code = ::primerdia::primerdia_tests::ENotImplemented)] +fun test_primerdia_fail() { + abort ENotImplemented +} +*/ From ffe8772af6e7743f2c5995641deeee0a4c87f831 Mon Sep 17 00:00:00 2001 From: AETHERGY4 Date: Mon, 17 Nov 2025 06:03:51 +0000 Subject: [PATCH 2/4] dia dos ejercicio --- PrimerDia/sources/primerdia.move | 49 +++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/PrimerDia/sources/primerdia.move b/PrimerDia/sources/primerdia.move index 406993e..a85b70a 100644 --- a/PrimerDia/sources/primerdia.move +++ b/PrimerDia/sources/primerdia.move @@ -1,15 +1,56 @@ module primerdia::modulo { use std::debug::print; + use std::string::utf8; - const GRAVEDAD: u8 = 10; + const CONSTANTE: u16 = 10; fun suma() { - let numero: u8 = 10; - print(&(numero + GRAVEDAD)) + let conversion: u8 = CONSTANTE as u8; + let mut numero: u8 = 10; + numero = 15u8; + //print(&(numero + conversion)); + //print(&(numero - conversion)); + //print(&(numero * conversion)); + //print(&(numero / conversion)); + //print(&(numero == conversion)); + print(&(numero != conversion)); + //print(&(numero > conversion)); + //print(&(numero < conversion)); + //print(&(numero >= conversion)); + //print(&(numero <= conversion)); + + //if(numero > conversion) { + //print(&(utf8(b"numero es mayor"))) + //}else if (numero < conversion) { + //print(&(utf8(b"numero es menor"))) + //}else { + //print(&(utf8(b"el numero es igual a al convercion"))) + //} + } + + fun contador(x: u8) { + let mut cuenta: u8 = 0; + //while(x > cuenta) { + //print(&cuenta); + //cuenta = cuenta + 1; + //} + + loop { + cuenta = cuenta +1; + if(cuenta > x) { + break + } else if((cuenta % 2) == 1) { + continue + } else { + print(&(utf8(b"numero es par"))); + }; + + print(&cuenta); + } } #[test] fun practica() { - suma() + contador(10) } } \ No newline at end of file From a6e874b601707ce5db104dcb57b3f1ab1eb86e16 Mon Sep 17 00:00:00 2001 From: AETHERGY4 Date: Mon, 17 Nov 2025 21:45:43 +0000 Subject: [PATCH 3/4] Dia 3 BaseDeDatos --- BaseDeDatos/.gitignore | 4 ++ BaseDeDatos/Move.toml | 36 +++++++++++++ BaseDeDatos/sources/basededatos.move | 65 ++++++++++++++++++++++++ BaseDeDatos/tests/basededatos_tests.move | 18 +++++++ 4 files changed, 123 insertions(+) create mode 100644 BaseDeDatos/.gitignore create mode 100644 BaseDeDatos/Move.toml create mode 100644 BaseDeDatos/sources/basededatos.move create mode 100644 BaseDeDatos/tests/basededatos_tests.move diff --git a/BaseDeDatos/.gitignore b/BaseDeDatos/.gitignore new file mode 100644 index 0000000..813de75 --- /dev/null +++ b/BaseDeDatos/.gitignore @@ -0,0 +1,4 @@ +build/* +traces/* +.trace +.coverage* diff --git a/BaseDeDatos/Move.toml b/BaseDeDatos/Move.toml new file mode 100644 index 0000000..35d6338 --- /dev/null +++ b/BaseDeDatos/Move.toml @@ -0,0 +1,36 @@ +[package] +name = "BaseDeDatos" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] + +# 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] +basededatos = "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" + diff --git a/BaseDeDatos/sources/basededatos.move b/BaseDeDatos/sources/basededatos.move new file mode 100644 index 0000000..8b3538c --- /dev/null +++ b/BaseDeDatos/sources/basededatos.move @@ -0,0 +1,65 @@ +module basededatos::basededatos { + use sui::vec_map::{VecMap, Self}; + use std::string::{utf8, String,}; + + + + public struct Informacion has key, store, copy, drop { + id:UID, + nombre: String, + usuarios:VecMap + } + + public struct Usuario has store, copy, drop { + nombre: String, + edad: u8, + tipo: TipoUsuario + } + + public enum TipoUsuario, has store, copy, drop { + Basico(Basico), + Pro(Pro), + } + + public struct Basico has store { + mensaje: String, + } + + public struct Pro has store { + mensaje: String, + } + + #[error] + const ERROR_NOMBRE_EXISTE: vector = b"ERROR, EL NOMBRE DE USUARIO YA EXISTE EN LA BASE DE DATOS, INTENTA CON OTRO NUEVO"; + const ERROR_USUARIO_NO_EXISTE: u16 = 404; + + public fun crear_usuario(nombre: String, ctx: &mut TxContext) { + base = Informacion { + id: new::object(ctx) + nombre, + usuarios: vec_map::empty() + }; + + transfer::transfer(base, tx_context::sender(ctx)); + } + + + public fun crear_usuario(informacion: &mut Informacion, nombre: String, edad: u8, tipo: u8){ + assert!(!informacion.contains(&nombre), ERROR_NOMBRE_EXISTE) + + let tipo_usuario = + if (tipo == 0) { + TipoUsuario::Basico(Basico { mensaje: string::utf8(b"Usuario Basico") }) + } else { + TipoUsuario::Pro(Pro { mensaje: string::utf8(b"Usuario Pro") }) + }; + + usuario = Usuario { + nombre, + edad, + tipo: tipo_usuario + }; + + informacion.insert(nombre, usuario); + } +} \ No newline at end of file diff --git a/BaseDeDatos/tests/basededatos_tests.move b/BaseDeDatos/tests/basededatos_tests.move new file mode 100644 index 0000000..0d8e875 --- /dev/null +++ b/BaseDeDatos/tests/basededatos_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module basededatos::basededatos_tests; +// uncomment this line to import the module +// use basededatos::basededatos; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_basededatos() { + // pass +} + +#[test, expected_failure(abort_code = ::basededatos::basededatos_tests::ENotImplemented)] +fun test_basededatos_fail() { + abort ENotImplemented +} +*/ From 879691eb3ae8c07721ef712c7e14885f6a51a719 Mon Sep 17 00:00:00 2001 From: AETHERGY4 Date: Mon, 17 Nov 2025 23:51:34 +0000 Subject: [PATCH 4/4] dia 4 errores y despliegue --- BaseDeDatos/sources/basededatos.move | 55 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/BaseDeDatos/sources/basededatos.move b/BaseDeDatos/sources/basededatos.move index 8b3538c..2c5c13f 100644 --- a/BaseDeDatos/sources/basededatos.move +++ b/BaseDeDatos/sources/basededatos.move @@ -1,10 +1,10 @@ module basededatos::basededatos { use sui::vec_map::{VecMap, Self}; - use std::string::{utf8, String,}; + use std::string::{utf8, String}; - public struct Informacion has key, store, copy, drop { + public struct Informacion has key, store { id:UID, nombre: String, usuarios:VecMap @@ -16,26 +16,27 @@ module basededatos::basededatos { tipo: TipoUsuario } - public enum TipoUsuario, has store, copy, drop { + public enum TipoUsuario has store, copy, drop { Basico(Basico), Pro(Pro), } - public struct Basico has store { + public struct Basico has store, copy, drop{ mensaje: String, } - public struct Pro has store { + public struct Pro has store, copy, drop { mensaje: String, } #[error] const ERROR_NOMBRE_EXISTE: vector = b"ERROR, EL NOMBRE DE USUARIO YA EXISTE EN LA BASE DE DATOS, INTENTA CON OTRO NUEVO"; + #[error] const ERROR_USUARIO_NO_EXISTE: u16 = 404; - public fun crear_usuario(nombre: String, ctx: &mut TxContext) { - base = Informacion { - id: new::object(ctx) + public fun crear_bd(nombre: String, ctx: &mut TxContext) { + let base = Informacion { + id: object::new(ctx), nombre, usuarios: vec_map::empty() }; @@ -43,23 +44,45 @@ module basededatos::basededatos { transfer::transfer(base, tx_context::sender(ctx)); } - public fun crear_usuario(informacion: &mut Informacion, nombre: String, edad: u8, tipo: u8){ - assert!(!informacion.contains(&nombre), ERROR_NOMBRE_EXISTE) - - let tipo_usuario = + assert!(!informacion.usuarios.contains(&nombre), ERROR_NOMBRE_EXISTE); + + let tipo_usuario = if (tipo == 0) { - TipoUsuario::Basico(Basico { mensaje: string::utf8(b"Usuario Basico") }) + TipoUsuario::Basico(Basico { mensaje: utf8(b"Usuario Basico") }) } else { - TipoUsuario::Pro(Pro { mensaje: string::utf8(b"Usuario Pro") }) + TipoUsuario::Pro(Pro { mensaje: utf8(b"Usuario Pro") }) }; - usuario = Usuario { + let usuario = Usuario { nombre, edad, tipo: tipo_usuario }; - informacion.insert(nombre, usuario); + informacion.usuarios.insert(nombre, usuario); + + } + + public fun modificar_usuario(informacion: &mut Informacion, nombre: String, edad: u8, tipo: u8) { + assert!(informacion.usuarios.contains(&nombre), ERROR_USUARIO_NO_EXISTE); + + let tipo_usuario = + if (tipo == 0) { + TipoUsuario::Basico(Basico { mensaje: utf8(b"Usuario Basico") }) + } else { + TipoUsuario::Pro(Pro { mensaje: utf8(b"Usuario Pro") }) + }; + + let info_usuario = informacion.usuarios.get_mut(&nombre); + + info_usuario.edad = edad; + info_usuario.tipo = tipo_usuario; + } + + public fun eliminar_usuario(informacion: &mut Informacion, nombre: String, edad: u8, tipo: u8) { + assert!(informacion.usuarios.contains(&nombre), ERROR_USUARIO_NO_EXISTE); + + informacion.usuarios.remove(&nombre); } } \ No newline at end of file