-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from pawanpaudel93/feat/wao
feat: wao integration
- Loading branch information
Showing
23 changed files
with
1,062 additions
and
707 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
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
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
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 |
---|---|---|
|
@@ -180,4 +180,7 @@ dist | |
|
||
|
||
# Package manager | ||
*.lockb | ||
*.lockb | ||
|
||
# ao-deploy | ||
dist |
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 |
---|---|---|
@@ -1,36 +1,80 @@ | ||
# my-ao-contract | ||
|
||
AO contract created using [create-ao-contract](https://github.com/pawanpaudel93/create-ao-contract) featuring [Busted](https://luarocks.org/modules/lunarmodules/busted) for testing and seamless deployment via [ao-deploy](https://github.com/pawanpaudel93/ao-deploy). | ||
AO contract created using [create-ao-contract](https://github.com/pawanpaudel93/create-ao-contract), featuring: | ||
|
||
- 🧪 **Testing**: [Busted](https://luarocks.org/modules/lunarmodules/busted) and [WAO](https://github.com/weavedb/wao) for testing | ||
- 🛠️ **Development Tools**: [arweave](https://github.com/crookse/arweave-lua) for testing, formatting and linting | ||
- 📦 **Deployment**: Seamless deployment using [ao-deploy](https://github.com/pawanpaudel93/ao-deploy) | ||
|
||
## Prerequisites | ||
|
||
1. Make sure you have [Lua](https://www.lua.org/start.html#installing) and [LuaRocks](https://github.com/luarocks/luarocks/wiki/Download) installed. | ||
1. Install [Lua](https://www.lua.org/start.html#installing) and [LuaRocks](https://github.com/luarocks/luarocks/wiki/Download). | ||
|
||
2. Install [arweave](https://luarocks.org/modules/crookse/arweave) using LuaRocks for testing purposes. | ||
2. **Install Dependencies**: | ||
|
||
```bash | ||
# Install Arweave Lua package | ||
luarocks install arweave | ||
|
||
# Install project dependencies | ||
npm install | ||
``` | ||
|
||
3. **[Recommended]** Install [Lua Language Server](https://luals.github.io/#install) to make development easier, safer, and faster!. On VSCode, install extension: [sumneko.lua](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) | ||
- Install AO & Busted addon using Lua Addon Manager. On VSCode, goto `View > Command Palette > Lua: Open Addon Manager` | ||
**Note**: `arweave` package relies on `busted` for its testing capabilities. | ||
|
||
3. **IDE Setup (Recommended)**: | ||
- Install [VSCode](https://code.visualstudio.com/) | ||
- Add the [Lua Language Server](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) extension. | ||
- Install AO & Busted addons via Command Palette (`View > Command Palette > Lua: Open Addon Manager`) | ||
|
||
## Usage | ||
## Development | ||
|
||
To install dependencies: | ||
To run tests, use: | ||
|
||
```bash | ||
npm install | ||
npm run test | ||
``` | ||
|
||
To run tests: | ||
To deploy the contract, use: | ||
|
||
```bash | ||
npm run test | ||
npm run deploy | ||
``` | ||
|
||
To deploy contract: | ||
To format the code, use: | ||
|
||
```bash | ||
npm run deploy | ||
npm run format | ||
``` | ||
|
||
To lint the code, use: | ||
|
||
```bash | ||
npm run lint | ||
``` | ||
|
||
## Project Structure | ||
|
||
``` | ||
my-ao-contract/ | ||
├── src/ # Contract source code | ||
├── test/ # Test files | ||
├── scripts/ # Utility scripts | ||
├── aod.config.js # ao-deploy configuration | ||
└── package.json # Project configuration | ||
``` | ||
|
||
## Contributing | ||
|
||
If you wish to contribute, please follow these steps: | ||
|
||
1. Fork the repository. | ||
2. Create a new branch (`git checkout -b feature-branch`). | ||
3. Commit your changes (`git commit -am 'Add some feature'`). | ||
4. Push to the branch (`git push origin feature-branch`). | ||
5. Create a new Pull Request. | ||
|
||
## Acknowledgments | ||
|
||
- Created using [create-ao-contract](https://github.com/pawanpaudel93/create-ao-contract) | ||
- Built for [AO](https://ao.arweave.net/) |
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
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
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,50 @@ | ||
/* eslint-disable no-undef */ | ||
import { glob } from "glob"; | ||
import { spawn } from "child_process"; | ||
|
||
// First find all Lua files | ||
const luaFiles = glob.sync("src/**/*.lua"); | ||
|
||
// Only proceed if we found files to format | ||
if (luaFiles.length === 0) { | ||
console.log("ℹ️ No Lua files found to format"); | ||
process.exit(0); | ||
} | ||
|
||
// Pass the actual files to the formatter | ||
const formatter = spawn("arweave", ["fmt", ...luaFiles], { | ||
stdio: ["inherit", "inherit", "pipe"], | ||
shell: true, | ||
}); | ||
|
||
formatter.on("error", (err) => { | ||
console.error("❌ Failed to start formatter:", err.message); | ||
process.exit(1); | ||
}); | ||
|
||
let hasError = false; | ||
|
||
formatter.stderr?.on("data", (data) => { | ||
hasError = true; | ||
console.error(`❌ Formatter error: ${data}`); | ||
}); | ||
|
||
// Modify exit handler to consider stderr output | ||
formatter.on("exit", (code, signal) => { | ||
if (code === 0 && !hasError) { | ||
console.log("✅ Formatting completed successfully"); | ||
} else { | ||
console.error(`❌ Formatter failed with ${signal ? `signal ${signal}` : `code ${code}`}`); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
// Modify close handler to be more specific | ||
formatter.on("close", (code, signal) => { | ||
if (code !== 0) { | ||
console.error( | ||
`⚠️ Formatter process closed unexpectedly ${signal ? `with signal ${signal}` : `with code ${code}`}` | ||
); | ||
process.exit(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
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
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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
local bint = require('.bint')(256) | ||
local bint = require(".bint")(256) | ||
local utils = require "src.utils.mod" | ||
|
||
local mod = {} | ||
|
||
function mod.burn(msg) | ||
assert(type(msg.Quantity) == 'string', 'Quantity is required!') | ||
assert(bint(msg.Quantity) <= bint(Balances[msg.From]), 'Quantity must be less than or equal to the current balance!') | ||
assert(type(msg.Quantity) == "string", "Quantity is required!") | ||
assert(bint(msg.Quantity) <= bint(Balances[msg.From]), | ||
"Quantity must be less than or equal to the current balance!") | ||
|
||
Balances[msg.From] = utils.subtract(Balances[msg.From], msg.Quantity) | ||
TotalSupply = utils.subtract(TotalSupply, msg.Quantity) | ||
|
||
ao.send({ | ||
Target = msg.From, | ||
Data = "Successfully burned " .. msg.Quantity | ||
Balances[msg.From] = utils.subtract(Balances[msg.From], msg.Quantity) | ||
TotalSupply = utils.subtract(TotalSupply, msg.Quantity) | ||
if msg.reply then | ||
msg.reply({ | ||
Data = "Successfully burned " .. msg.Quantity | ||
}) | ||
else | ||
Send({ | ||
Target = msg.From, | ||
Data = "Successfully burned " .. msg.Quantity | ||
}) | ||
end | ||
end | ||
|
||
return mod |
Oops, something went wrong.