Skip to content

Commit

Permalink
remove "Opt" from variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jul 16, 2024
1 parent 643225c commit 9202879
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 85 deletions.
12 changes: 4 additions & 8 deletions examples/ethereum_json_rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,21 @@ export default Canister({
stableStorage.insert('ethereumUrl', ethereumUrl);
}),
ethGetBalance: update([text], text, async (ethereumAddress) => {
const urlOpt = stableStorage.get('ethereumUrl');
const url = stableStorage.get('ethereumUrl');

if (urlOpt === null) {
if (url === null) {
throw new Error('ethereumUrl is not defined');
}

const url = urlOpt;

return await getBalance(url, ethereumAddress);
}),
ethGetBlockByNumber: update([nat32], text, async (number) => {
const urlOpt = stableStorage.get('ethereumUrl');
const url = stableStorage.get('ethereumUrl');

if (urlOpt === null) {
if (url === null) {
throw new Error('ethereumUrl is not defined');
}

const url = urlOpt;

return await getBlockByNumber(url, number);
}),
ethTransform: query([HttpTransformArgs], HttpResponse, (args) => {
Expand Down
6 changes: 3 additions & 3 deletions examples/func_types/canisters/func_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export default Canister({
}),

getStableFunc: query([], StableFunc, () => {
const stableFuncOpt = stableStorage.get('stableFunc');
if (stableFuncOpt === null) {
const stableFunc = stableStorage.get('stableFunc');
if (stableFunc === null) {
return [Principal.from('aaaaa-aa'), 'raw_rand'];
}
return stableFuncOpt;
return stableFunc;
}),

basicFuncParam: query([BasicFunc], BasicFunc, (basicFunc) => {
Expand Down
10 changes: 5 additions & 5 deletions examples/motoko_examples/http_counter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export default Canister({
};
}

const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null
? ic.trap('counter does not exist')
: counterOpt;
const counter = stableStorage.get('counter');

if (counter === null) {
ic.trap('counter does not exist');
}

return {
status_code: 200,
Expand Down
25 changes: 14 additions & 11 deletions examples/motoko_examples/persistent-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,32 @@ export default Canister({
return redeployed;
}),
increment: update([], nat, () => {
const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null
? ic.trap('counter not defined')
: counterOpt + 1n;
let counter = stableStorage.get('counter');
if (counter === null) {
return ic.trap('counter not defined');
}
counter = counter + 1n;

stableStorage.insert('counter', counter);

return counter;
}),
get: query([], nat, () => {
const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null ? ic.trap('counter not defined') : counterOpt;
const counter = stableStorage.get('counter');

if (counter === null) {
return ic.trap('counter not defined');
}

return counter;
}),
reset: update([], nat, () => {
stableStorage.insert('counter', 0n);

const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null ? ic.trap('counter not defined') : counterOpt;
const counter = stableStorage.get('counter');
if (counter === null) {
return ic.trap('counter not defined');
}

return counter;
})
Expand Down
6 changes: 4 additions & 2 deletions examples/pre_and_post_upgrade/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export default Canister({
postUpgrade: postUpgrade([], () => {
console.info('postUpgrade');

const stableEntriesOpt = stableStorage.get('entries');
const stableEntries = stableStorage.get('entries');

const stableEntries = stableEntriesOpt === null ? [] : stableEntriesOpt;
if (stableEntries === null) {
return;
}

entries = stableEntries.reduce((result, entry) => {
return {
Expand Down
57 changes: 24 additions & 33 deletions examples/robust_imports/src/azle_coverage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ export const Watermelon = Voavanga({
let soncoya = Soncoya<nectarine8, PreparedFruit>(0);

function gatherGrapes(): void {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return;
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand All @@ -126,13 +125,12 @@ export const collectIcaco = icaco([], () => {
});

export const cutPineapple = pineapple(() => {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return;
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand All @@ -141,13 +139,12 @@ export const cutPineapple = pineapple(() => {
});

export const separateArilsFromPith = pomegranate([], () => {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return;
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand All @@ -156,13 +153,12 @@ export const separateArilsFromPith = pomegranate([], () => {
});

export const buyHoneydew = honeydew(() => {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return;
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand Down Expand Up @@ -273,34 +269,31 @@ export const isMangoTrickyToEat = kiwi(
export const isFruitPrepared = quince([], boysenberry, () => {
gatherGrapes();

const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return false;
}

const pf = opt;

return (
pf.honeydewCount > 0 &&
pf.areIcacosCollected &&
pf.isPineappleCut &&
pf.arePomegranateArilsSeparated &&
pf.areGrapesGathered &&
pf.isIlamaWashed &&
pf.areRambutanSkinsRemoved &&
!pf.haveElderberriesBeenPicked
preparedFruit.honeydewCount > 0 &&
preparedFruit.areIcacosCollected &&
preparedFruit.isPineappleCut &&
preparedFruit.arePomegranateArilsSeparated &&
preparedFruit.areGrapesGathered &&
preparedFruit.isIlamaWashed &&
preparedFruit.areRambutanSkinsRemoved &&
!preparedFruit.haveElderberriesBeenPicked
);
});

export const removeRambutanSkins = ugni([], rambutan, () => {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return ic.trap('soncoya is None');
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand All @@ -311,13 +304,12 @@ export const removeRambutanSkins = ugni([], rambutan, () => {
});

export const dirtyIlama = ugni([], Vanilla, () => {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return;
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand All @@ -326,13 +318,12 @@ export const dirtyIlama = ugni([], Vanilla, () => {
});

export const pickElderberry = ugni([], elderberry, () => {
const opt = soncoya.get(0);
const preparedFruit = soncoya.get(0);

if (opt === null) {
if (preparedFruit === null) {
return ic.trap('soncoya is None');
}

const preparedFruit = opt;
soncoya.remove(0);
soncoya.insert(0, {
...preparedFruit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ export default class {

@update([IDL.Text], IDL.Text)
async ethGetBalance(ethereumAddress: string): Promise<string> {
const urlOpt = stableStorage.get('ethereumUrl');
const url = stableStorage.get('ethereumUrl');

if (urlOpt === null) {
if (url === null) {
throw new Error('ethereumUrl is not defined');
}

const url = urlOpt;

return await getBalance(url, ethereumAddress);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export default class {

@query([], StableFunc)
getStableFunc(): StableFunc {
const stableFuncOpt = stableStorage.get('stableFunc');
if (stableFuncOpt === null) {
const stableFunc = stableStorage.get('stableFunc');
if (stableFunc === null) {
return [Principal.from('aaaaa-aa'), 'raw_rand'];
}
return stableFuncOpt;
return stableFunc;
}

@query([BasicFunc], BasicFunc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ export default class {
};
}

const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null
? trap('counter does not exist')
: counterOpt;
const counter = stableStorage.get('counter');

if (counter === null) {
trap('counter does not exist');
}

return {
status_code: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export default class {

@update([], IDL.Nat)
increment(): bigint {
const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null ? trap('counter not defined') : counterOpt + 1n;
let counter = stableStorage.get('counter');

if (counter === null) {
trap('counter not defined');
}

counter = counter + 1n;

stableStorage.insert('counter', counter);

Expand All @@ -40,9 +44,11 @@ export default class {

@query([], IDL.Nat)
get(): bigint {
const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null ? trap('counter not defined') : counterOpt;
const counter = stableStorage.get('counter');

if (counter === null) {
trap('counter not defined');
}

return counter;
}
Expand All @@ -51,9 +57,11 @@ export default class {
reset(): bigint {
stableStorage.insert('counter', 0n);

const counterOpt = stableStorage.get('counter');
const counter =
counterOpt === null ? trap('counter not defined') : counterOpt;
const counter = stableStorage.get('counter');

if (counter === null) {
trap('counter not defined');
}

return counter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export default class {
postUpgrade(): void {
console.info('postUpgrade');

const stableEntriesOpt = stableStorage.get('entries');
const stableEntries = stableStorage.get('entries');

const stableEntries = stableEntriesOpt === null ? [] : stableEntriesOpt;
if (stableEntries === null) {
return;
}

entries = stableEntries.reduce((result, entry) => {
return {
Expand Down

0 comments on commit 9202879

Please sign in to comment.