diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..119d4df --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: "release" + +on: + push: + tags: + - '*' + +jobs: + release: + name: "Release" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + - uses: cachix/install-nix-action@v13 + with: + nix_path: nixpkgs=channel:nixos-21.05 + - uses: cachix/cachix-action@v10 + with: + name: ninegua + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix-build + - name: Upload release package + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref }} + file: result/bin/* + file_glob: true diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5edf35d --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +CANISTERS=blackhole +SRC=$(CANISTERS:%=src/%.mo) +OBJ=$(CANISTERS:%=dist/%.wasm) +OBJ_OPT=$(CANISTERS:%=dist/%-opt.wasm) +IDL=$(CANISTERS:%=dist/%.did) +MOC_OPT=--package base .vessel/base/927119e172964f4038ebc7018f9cc1b688544bfa/src + +build: $(OBJ) $(IDL) $(OBJ_OPT) + +clean: + rm -f dist + +dist: + @mkdir -p $@ + +dist/%.wasm: src/%.mo | dist + moc $(MOC_OPT) -o $@ $< + +dist/%.did: src/%.mo | dist + moc $(MOC_OPT) --idl -o $@ $< + +.PHONY: build clean really-clean + +UTIL_DIR?=/nix/store/4gaariri115lys3l5mfip6knn0v78clp-ic-utils +include $(UTIL_DIR)/share/mk/inc.mk diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..cdc60f8 --- /dev/null +++ b/default.nix @@ -0,0 +1,23 @@ +{ pkgs ? import { } }: +let + ic-utils = import (builtins.fetchGit { + url = "http://github.com/ninegua/ic-utils"; + rev = "56d404d73dd5253372a1d50997df51e2ddc4d6fb"; + }) { inherit pkgs; }; + motoko-base = builtins.fetchGit { + url = "https://github.com/dfinity/motoko-base"; + rev = "927119e172964f4038ebc7018f9cc1b688544bfa"; + }; +in pkgs.stdenv.mkDerivation { + name = "ic-blackhole"; + version = "0.0.0"; + phases = [ "buildPhase" "installPhase" ]; + src = ./.; + nativeBuildInputs = [ pkgs.binaryen ]; + buildPhase = '' + export PATH=${ic-utils}/bin:$PATH + cp -r $src/* . + make MOC_OPT='--package base ${motoko-base}/src/' UTIL_DIR='${ic-utils}' + ''; + installPhase = "mkdir -p $out/bin && install -m 644 dist/* $out/bin/"; +} diff --git a/src/blackhole.mo b/src/blackhole.mo new file mode 100644 index 0000000..694fae5 --- /dev/null +++ b/src/blackhole.mo @@ -0,0 +1,32 @@ +import Nat "mo:base/Nat"; +import Nat8 "mo:base/Nat8"; +import Principal "mo:base/Principal"; + +actor { + public type canister_id = Principal; + + public type definite_canister_settings = { + freezing_threshold : Nat; + controllers : [Principal]; + memory_allocation : Nat; + compute_allocation : Nat; + }; + + public type canister_status = { + status : { #stopped; #stopping; #running }; + memory_size : Nat; + cycles : Nat; + settings : definite_canister_settings; + module_hash : ?[Nat8]; + }; + + public type IC = actor { + canister_status : { canister_id : canister_id } -> async canister_status; + }; + + let ic : IC = actor("aaaaa-aa"); + + public func canister_status(request : { canister_id : canister_id }) : async canister_status { + await ic.canister_status(request) + } +}