Skip to content

Commit

Permalink
[Platform][API]GetUpgradePhases + example
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d authored and knikos committed Jun 28, 2023
1 parent 7f1e0cb commit a852d7d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/platformvm/buildAddressStateTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const InitAvalanche = async () => {
await avalanche.fetchNetworkSettings()
pchain = avalanche.PChain()
pKeychain = pchain.keyChain()
// X-kopernikus1g65uqn6t77p656w64023nh8nd9updzmxh8ttv3
// P-kopernikus1g65uqn6t77p656w64023nh8nd9updzmxh8ttv3
pKeychain.importKey(privKey)

pAddressStrings = pchain.keyChain().getAddressStrings()
Expand All @@ -47,6 +47,7 @@ const main = async (): Promise<any> => {
)

const unsignedTx: UnsignedTx = await pchain.buildAddressStateTx(
0,
undefined,
pAddressStrings,
pAddressStrings,
Expand Down
1 change: 1 addition & 0 deletions examples/platformvm/buildDepositTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const main = async (): Promise<any> => {
)

const unsignedTx: UnsignedTx = await pchain.buildDepositTx(
0,
undefined,
pAddressStrings,
pAddressStrings,
Expand Down
1 change: 0 additions & 1 deletion examples/platformvm/getUpgradePhases.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Avalanche } from "caminojs/index"
import { PlatformVMAPI } from "caminojs/apis/platformvm"
import { ExamplesConfig } from "../common/examplesConfig"
import { json } from "stream/consumers"

const config: ExamplesConfig = require("../common/examplesConfig.json")
const avalanche: Avalanche = new Avalanche(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Camino Platform JS Library",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && npx tsc -b",
"build": "rm -rf dist && npx tsc -b tsconfig_build.json",
"bundle": "webpack --mode production",
"docshtml": "npx typedoc --plugin typedoc-plugin-external-module-name --mode file src",
"docsmd": "npx typedoc --readme none --plugin typedoc-plugin-markdown,typedoc-plugin-external-module-name --theme markdown --out docsMD src",
Expand Down
17 changes: 16 additions & 1 deletion src/apis/platformvm/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ import {
GetDepositsResponse,
Owner,
OwnerParam,
MultisigAliasParams
MultisigAliasParams,
UpgradePhasesReply
} from "./interfaces"
import { TransferableInput } from "./inputs"
import { TransferableOutput } from "./outputs"
Expand Down Expand Up @@ -737,6 +738,20 @@ export class PlatformVMAPI extends JRPCAPI {
return response.data.result
}

/**
* Retrieves the current phases.
*
* @returns Returns a Promise of a UpgradePhasesReply.
*/
getUpgradePhases = async (): Promise<UpgradePhasesReply> => {
const response: RequestResponseData = await this.callMethod(
"platform.getUpgradePhases"
)
return {
SunrisePhase: parseInt(response.data.result.sunrisePhase)
}
}

/**
* Samples `Size` validators from the current validator set.
*
Expand Down
4 changes: 4 additions & 0 deletions src/apis/platformvm/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,7 @@ export interface ClaimAmountParams {
owners: OutputOwners
sigIdxs: number[]
}

export interface UpgradePhasesReply {
SunrisePhase: number
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"caminojs/*": ["./src/*"]
}
},
"exclude": ["node_modules", "examples_", "*/**/*.test.ts", "e2e_tests"],
"include": ["src/"],
"exclude": ["node_modules", "*/**/*.test.ts", "e2e_tests"],
"include": ["src/", "examples/"],
"typeAcquisition": {
"enable": true,
"exclude": ["bn.js"]
Expand Down
28 changes: 28 additions & 0 deletions tsconfig_build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"outDir": "./dist/",
"baseUrl": ".",
"module": "commonjs",
"target": "ES2015",
"lib": ["dom", "es2016"],
"declaration": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"inlineSourceMap": true,
"inlineSources": true,
"declarationMap": true,
"noFallthroughCasesInSwitch": true,
"strictFunctionTypes": true,
"esModuleInterop": true,
"typeRoots": ["./typings/**", "./node_modules/@types"],
"paths": {
"caminojs/*": ["./src/*"]
}
},
"exclude": ["node_modules", "*/**/*.test.ts", "e2e_tests"],
"include": ["src/"],
"typeAcquisition": {
"enable": true,
"exclude": ["bn.js"]
}
}

0 comments on commit a852d7d

Please sign in to comment.