-
Notifications
You must be signed in to change notification settings - Fork 37
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 #1261 from demergent-labs/functional_syntax_cycles
Functional syntax cycles
- Loading branch information
Showing
10 changed files
with
298 additions
and
153 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 was deleted.
Oops, something went wrong.
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,24 +1,17 @@ | ||
import { ic, nat, nat64, query, Service, update } from 'azle'; | ||
|
||
export default class extends Service { | ||
@update([], nat64) | ||
receiveCycles(): nat64 { | ||
export default Service({ | ||
receiveCycles: update([], nat64, () => { | ||
return ic.msgCyclesAccept(ic.msgCyclesAvailable() / 2n); | ||
} | ||
|
||
}), | ||
// Moves all transferred cycles to the canister | ||
@update([], nat) | ||
receiveCycles128(): nat { | ||
receiveCycles128: update([], nat, () => { | ||
return ic.msgCyclesAccept128(ic.msgCyclesAvailable128() / 2n); | ||
} | ||
|
||
@query([], nat64) | ||
getCanisterBalance(): nat64 { | ||
}), | ||
getCanisterBalance: query([], nat64, () => { | ||
return ic.canisterBalance(); | ||
} | ||
|
||
@query([], nat) | ||
getCanisterBalance128(): nat { | ||
}), | ||
getCanisterBalance128: query([], nat, () => { | ||
return ic.canisterBalance128(); | ||
} | ||
} | ||
}) | ||
}); |
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,53 +1,55 @@ | ||
import { ic, nat, nat64, Principal, query, Service, update, Void } from 'azle'; | ||
import { | ||
ic, | ||
init, | ||
nat, | ||
nat64, | ||
Principal, | ||
query, | ||
Service, | ||
update, | ||
Void | ||
} from 'azle'; | ||
import Cycles from '../cycles'; | ||
|
||
export default class extends Service { | ||
cyclesCanister = new Cycles( | ||
Principal.fromText( | ||
process.env.CYCLES_PRINCIPAL ?? | ||
ic.trap('process.env.CYCLES_PRINCIPAL is undefined') | ||
) | ||
); | ||
|
||
let cyclesCanister: typeof Cycles; | ||
|
||
export default Service({ | ||
init: init([], () => { | ||
cyclesCanister = Cycles( | ||
Principal.fromText( | ||
process.env.CYCLES_PRINCIPAL ?? | ||
ic.trap('process.env.CYCLES_PRINCIPAL is undefined') | ||
) | ||
); | ||
}), | ||
// Reports the number of cycles returned from the Cycles canister | ||
@update([], nat64) | ||
async sendCycles(): Promise<nat64> { | ||
return await ic.call(this.cyclesCanister.receiveCycles, { | ||
sendCycles: update([], nat64, async () => { | ||
return await ic.call(cyclesCanister.receiveCycles, { | ||
cycles: 1_000_000n | ||
}); | ||
} | ||
|
||
@update([], Void) | ||
sendCyclesNotify(): Void { | ||
return ic.notify(this.cyclesCanister.receiveCycles, { | ||
}), | ||
sendCyclesNotify: update([], Void, () => { | ||
return ic.notify(cyclesCanister.receiveCycles, { | ||
cycles: 1_000_000n | ||
}); | ||
} | ||
|
||
}), | ||
// Reports the number of cycles returned from the Cycles canister | ||
@update([], nat) | ||
async sendCycles128(): Promise<nat> { | ||
await ic.call(this.cyclesCanister.receiveCycles128, { | ||
sendCycles128: update([], nat, async () => { | ||
await ic.call(cyclesCanister.receiveCycles128, { | ||
cycles: 1_000_000n | ||
}); | ||
|
||
return ic.msgCyclesRefunded128(); | ||
} | ||
|
||
@update([], Void) | ||
sendCycles128Notify(): Void { | ||
return ic.notify(this.cyclesCanister.receiveCycles128, { | ||
}), | ||
sendCycles128Notify: update([], Void, () => { | ||
return ic.notify(cyclesCanister.receiveCycles128, { | ||
cycles: 1_000_000n | ||
}); | ||
} | ||
|
||
@query([], nat64) | ||
getCanisterBalance(): nat64 { | ||
}), | ||
getCanisterBalance: query([], nat64, () => { | ||
return ic.canisterBalance(); | ||
} | ||
|
||
@query([], nat) | ||
getCanisterBalance128(): nat { | ||
}), | ||
getCanisterBalance128: query([], nat, () => { | ||
return ic.canisterBalance128(); | ||
} | ||
} | ||
}) | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.