Transaction

A1F76818416E47…1E39B8F6616D

Block 25,997 · index 0 · indexed

Summary

Hash
A1F76818416E4744FE8AB5732EE5B8B8EAAB70A81441AE7C8A091E39B8F6616D
Block
25,997
Size
5057 bytes
Gas used
9,525,988 / 11,431,245
Fee
1000000ugnot
Memo
gnopublish
Status
success

Messages

#1AddPackagegno.land/r/moul/x/daily/calc/v09 arguments

Arguments · 9

  1. #1calc
  2. #2README.md
  3. #3# RPN Calculator > ⚠️ **Experimental — generated with no human supervision.** This realm was > produced automatically by an MCP-driven agent to exercise the gno MCP server > and tooling, and to generate test content for gno compilers, linters and > formatters. **Not audited. Not for production.** Full context & folder README: > [r/moul/x/daily](https://github.com/moul/gno-contracts/blob/main/r/moul/x/daily/README.md) --- A shared, stack-based Reverse Polish Notation calculator realm. Anyone can push tokens onto a single shared stack: integers are pushed as-is, while an operator (`+`, `-`, `*`, `/`) pops the top two operands and pushes the result. Divide-by-zero and stack underflow abort the transaction, and `Clear` resets the stack. `Render` shows the current stack (bottom→top), the top value as the result, and a usage guide. ## Realm path `gno.land/r/REPLACE_ADDR/calc` ## Example calls ``` # Compute (5 3 +) = 8 Push("5") Push("3") Push("+") # Chain: (10 4 -) 2 * = 12 Push("10") Push("4") Push("-") Push("2") Push("*") # Reset Clear() ``` Read the current state via `Render` (e.g. the realm's rendered page). <!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) --> --- Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage. > 🧪 **Highly experimental — potentially vibe-coded.** Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
  4. #4calc.gno
  5. #5package calc import ( "chain" "errors" "strconv" "strings" ) // stack holds the shared RPN operand stack, bottom (index 0) to top. var stack []int // ErrUnderflow is raised when an operator needs more operands than available. var ErrUnderflow = errors.New("stack underflow: operator needs two operands") // ErrDivByZero is raised on division by zero. var ErrDivByZero = errors.New("division by zero") // Push consumes a single token: an integer is pushed onto the stack; an // operator (+, -, *, /) pops two operands and pushes the result. func Push(cur realm, token string) { token = strings.TrimSpace(token) if token == "" { panic("empty token") } switch token { case "+", "-", "*", "/": if len(stack) < 2 { panic(ErrUnderflow.Error()) } b := stack[len(stack)-1] a := stack[len(stack)-2] stack = stack[:len(stack)-2] var r int switch token { case "+": r = a + b case "-": r = a - b case "*": r = a * b case "/": if b == 0 { panic(ErrDivByZero.Error()) } r = a / b } stack = append(stack, r) chain.Emit("Op", "op", token, "result", strconv.Itoa(r)) default: n, err := strconv.Atoi(token) if err != nil { panic("invalid token: expected integer or one of + - * /, got " + token) } stack = append(stack, n) chain.Emit("Push", "value", strconv.Itoa(n)) } } // Clear empties the shared stack. func Clear(cur realm) { stack = nil chain.Emit("Clear") } // Depth returns the number of values currently on the stack. func Depth() int { return len(stack) } // Top returns the top value and whether the stack is non-empty. func Top() (int, bool) { if len(stack) == 0 { return 0, false } return stack[len(stack)-1], true } // Render renders the current stack, the top value as the result, and a // short usage guide. func Render(path string) string { var sb strings.Builder sb.WriteString("# RPN Calculator\n\n") sb.WriteString("## Result\n\n") if top, ok := Top(); ok { sb.WriteString("**") sb.WriteString(strconv.Itoa(top)) sb.WriteString("**\n\n") } else { sb.WriteString("_(empty stack)_\n\n") } sb.WriteString("## Stack (bottom → top)\n\n") if len(stack) == 0 { sb.WriteString("_empty_\n\n") } else { for i, v := range stack { sb.WriteString(strconv.Itoa(i)) sb.WriteString(". ") sb.WriteString(strconv.Itoa(v)) sb.WriteString("\n") } sb.WriteString("\n") } sb.WriteString("## Usage\n\n") sb.WriteString("Reverse Polish Notation: operands first, operator last.\n\n") sb.WriteString("- `Push(\"5\")` then `Push(\"3\")` then `Push(\"+\")` → `8`\n") sb.WriteString("- Supported operators: `+`, `-`, `*`, `/` (integer division)\n") sb.WriteString("- An operator pops the top two values (a, b) and pushes `a op b`.\n") sb.WriteString("- `Clear()` empties the stack.\n") sb.WriteString("- Divide-by-zero and underflow abort the transaction.\n") return sb.String() }
  6. #6gnomod.toml
  7. #7module = "gno.land/r/moul/x/daily/calc/v0" gno = "0.9"
  8. #8/gno.MemPackageType
  9. #9 MPUserProd

Result log

msg:0,success:true,log:,events:[]

← Back to block 25,997