-
Notifications
You must be signed in to change notification settings - Fork 2
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 #72 from citycoins/develop
V2 Release: multiple version support
- Loading branch information
Showing
65 changed files
with
2,863 additions
and
1,180 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// activation exports | ||
|
||
export { default as GetActivationBlock } from './activation/getactivationblock' | ||
export { default as GetActivationTarget } from './activation/getactivationtarget' | ||
export { default as GetCityWallet } from './activation/getcitywallet' | ||
export { default as GetRegisteredUsersNonce } from './activation/getregisteredusersnonce' | ||
export { default as GetUser } from './activation/getuser' | ||
export { default as GetUserId } from './activation/getuserid' |
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,29 +1,38 @@ | ||
import { Request as IttyRequest } from 'itty-router' | ||
import { getActivationBlock } from '../../lib/citycoins' | ||
import { createSingleValue } from '../../lib/common' | ||
import { getCityConfig } from '../../types/cities' | ||
import { createResponse } from '../../lib/common' | ||
import { CityConfig, getCityConfig } from '../../types/cities' | ||
import { SingleValue } from '../../types/common' | ||
|
||
const GetActivationBlock = async (request: IttyRequest): Promise<Response> => { | ||
let cityConfig: CityConfig | ||
let activationBlock: string | ||
let response: SingleValue | boolean | number | string | ||
// check inputs | ||
const version = request.params?.version ?? undefined | ||
const city = request.params?.cityname ?? undefined | ||
if (city === undefined) { | ||
return new Response(`Invalid request, missing parameter(s)`, { status: 400 }) | ||
if (version === undefined || city === undefined) { | ||
return new Response(`Invalid request, missing parameter(s)`, { | ||
status: 400, | ||
}) | ||
} | ||
// get city configuration object | ||
const cityConfig = await getCityConfig(city) | ||
if (cityConfig.deployer === '') { | ||
return new Response(`City name not found: ${city}`, { status: 404 }) | ||
// check response output format | ||
let format = 'json' | ||
const { query } = request | ||
if (Object.prototype.hasOwnProperty.call(query, 'format')) { | ||
if (query?.format !== undefined) format = query.format | ||
} | ||
// get activation block | ||
const activationBlock = await getActivationBlock(cityConfig) | ||
// return response | ||
const response: SingleValue = await createSingleValue(activationBlock) | ||
const headers = { | ||
'Access-Control-Allow-Origin': '*', | ||
'Content-Type': 'application/json', | ||
// get/calculate response | ||
try { | ||
cityConfig = await getCityConfig(city, version) | ||
activationBlock = await getActivationBlock(cityConfig) | ||
response = await createResponse(activationBlock, format) | ||
} catch (err) { | ||
if (err instanceof Error) return new Response(err.message, { status: 404 }) | ||
return new Response(String(err), { status: 404 }) | ||
} | ||
return new Response(JSON.stringify(response), { headers }) | ||
// return response | ||
return new Response(JSON.stringify(response)) | ||
} | ||
|
||
export default GetActivationBlock |
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,38 @@ | ||
import { Request as IttyRequest } from 'itty-router' | ||
import { getActivationTarget } from '../../lib/citycoins' | ||
import { createResponse } from '../../lib/common' | ||
import { CityConfig, getCityConfig } from '../../types/cities' | ||
import { SingleValue } from '../../types/common' | ||
|
||
const GetActivationTarget = async (request: IttyRequest): Promise<Response> => { | ||
let cityConfig: CityConfig | ||
let activationTarget: string | ||
let response: SingleValue | boolean | number | string | ||
// check inputs | ||
const version = request.params?.version ?? undefined | ||
const city = request.params?.cityname ?? undefined | ||
if (version === undefined || city === undefined) { | ||
return new Response(`Invalid request, missing parameter(s)`, { | ||
status: 400, | ||
}) | ||
} | ||
// check response output format | ||
let format = 'json' | ||
const { query } = request | ||
if (Object.prototype.hasOwnProperty.call(query, 'format')) { | ||
if (query?.format !== undefined) format = query.format | ||
} | ||
// get/calculate response | ||
try { | ||
cityConfig = await getCityConfig(city, version) | ||
activationTarget = await getActivationTarget(cityConfig) | ||
response = await createResponse(activationTarget, format) | ||
} catch (err) { | ||
if (err instanceof Error) return new Response(err.message, { status: 404 }) | ||
return new Response(String(err), { status: 404 }) | ||
} | ||
// return response | ||
return new Response(JSON.stringify(response)) | ||
} | ||
|
||
export default GetActivationTarget |
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,38 @@ | ||
import { Request as IttyRequest } from 'itty-router' | ||
import { getCityWallet } from '../../lib/citycoins' | ||
import { createResponse } from '../../lib/common' | ||
import { CityConfig, getCityConfig } from '../../types/cities' | ||
import { SingleValue } from '../../types/common' | ||
|
||
const GetCityWallet = async (request: IttyRequest): Promise<Response> => { | ||
let cityConfig: CityConfig | ||
let cityWallet: string | ||
let response: SingleValue | boolean | number | string | ||
// check inputs | ||
const version = request.params?.version ?? undefined | ||
const city = request.params?.cityname ?? undefined | ||
if (version === undefined || city === undefined) { | ||
return new Response(`Invalid request, missing parameter(s)`, { | ||
status: 400, | ||
}) | ||
} | ||
// check response output format | ||
let format = 'json' | ||
const { query } = request | ||
if (Object.prototype.hasOwnProperty.call(query, 'format')) { | ||
if (query?.format !== undefined) format = query.format | ||
} | ||
// get/calculate response | ||
try { | ||
cityConfig = await getCityConfig(city, version) | ||
cityWallet = await getCityWallet(cityConfig) | ||
response = await createResponse(cityWallet, format) | ||
} catch (err) { | ||
if (err instanceof Error) return new Response(err.message, { status: 404 }) | ||
return new Response(String(err), { status: 404 }) | ||
} | ||
// return response | ||
return new Response(JSON.stringify(response)) | ||
} | ||
|
||
export default GetCityWallet |
Oops, something went wrong.