Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/407 update vda node xxx packages #408

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/vda-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-03-22 (v3.0.2)
-------------------

- Update the abi & address of `StorageNodeRegistry` contract

2024-03-15 (v3.0.1)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion packages/vda-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@verida/vda-common",
"version": "3.0.1",
"version": "3.0.2",
"description": "Common utils & contract addresses for Verida",
"main": "dist/index.js",
"author": "Alex J",
Expand Down
70 changes: 70 additions & 0 deletions packages/vda-common/src/abi/StorageNodeRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@
}
]
},
{
"type": "function",
"name": "acceptOwnership",
"constant": false,
"payable": false,
"inputs": [],
"outputs": []
},
{
"type": "function",
"name": "cancelTransferOwnership",
"constant": false,
"payable": false,
"inputs": [],
"outputs": []
},
{
"type": "function",
"name": "owner",
Expand All @@ -145,6 +161,20 @@
}
]
},
{
"type": "function",
"name": "pendingOwner",
"constant": true,
"stateMutability": "view",
"payable": false,
"inputs": [],
"outputs": [
{
"type": "address",
"name": "pendingOwner_"
}
]
},
{
"type": "function",
"name": "transferOwnership",
Expand Down Expand Up @@ -1436,6 +1466,14 @@
{
"type": "string",
"name": "countryCode"
},
{
"type": "uint256",
"name": "pageSize"
},
{
"type": "uint256",
"name": "pageNumber"
}
],
"outputs": [
Expand Down Expand Up @@ -1517,6 +1555,14 @@
{
"type": "uint8",
"name": "status"
},
{
"type": "uint256",
"name": "pageSize"
},
{
"type": "uint256",
"name": "pageNumber"
}
],
"outputs": [
Expand Down Expand Up @@ -1594,6 +1640,14 @@
{
"type": "string",
"name": "regionCode"
},
{
"type": "uint256",
"name": "pageSize"
},
{
"type": "uint256",
"name": "pageNumber"
}
],
"outputs": [
Expand Down Expand Up @@ -1675,6 +1729,14 @@
{
"type": "uint8",
"name": "status"
},
{
"type": "uint256",
"name": "pageSize"
},
{
"type": "uint256",
"name": "pageNumber"
}
],
"outputs": [
Expand Down Expand Up @@ -1752,6 +1814,14 @@
{
"type": "uint8",
"name": "status"
},
{
"type": "uint256",
"name": "pageSize"
},
{
"type": "uint256",
"name": "pageNumber"
}
],
"outputs": [
Expand Down
6 changes: 3 additions & 3 deletions packages/vda-common/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export const CONTRACT_ADDRESS : Record<CONTRACT_NAMES, Record<string, string | n
"StorageNodeRegistry": {
mainnet: null,
"0x89": null,
testnet: "0x044B2D754923e529A780eFcc085B03ee022e3364",
"0x13881": "0x044B2D754923e529A780eFcc085B03ee022e3364",
devnet: "0x044B2D754923e529A780eFcc085B03ee022e3364"
testnet: "0xDfe326357A4078A3ea8A192084255F25Ab73c712",
"0x13881": "0xDfe326357A4078A3ea8A192084255F25Ab73c712",
devnet: "0xDfe326357A4078A3ea8A192084255F25Ab73c712"
}
};

Expand Down
5 changes: 4 additions & 1 deletion packages/vda-node-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
2024-03-15 (v3.0.0)
2024-03-15 (v3.0.2)
-------------------
- Added pagination for `getNodesBy...()` functions

2024-03-15 (v3.0.0)
-------------------
- Initial release
2 changes: 1 addition & 1 deletion packages/vda-node-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@verida/vda-node-client",
"version": "3.0.1",
"version": "3.0.2",
"description": "Client library that read nodat & datacentre information.",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
36 changes: 29 additions & 7 deletions packages/vda-node-client/src/blockchain/blockchainApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,61 +293,83 @@ export class VeridaNodeClient {
/**
* Get nodes by country and status
* @param countryCode Country code of nodes
* @param pageSize Number of maximum elements of returned
* @param pageNumber Page index. Index starts from 1
* @param status Status of nodes
*/
public async getNodesByCountryCode(
countryCode: string,
countryCode: string,
pageSize: BigNumberish,
pageNumber: BigNumberish,
status?: EnumStatus) {
if (status === undefined) {
return await this.executeFunction(
'getNodesByCountryCode',
'Failed to get nodes by country',
countryCode
countryCode,
pageSize,
pageNumber
);
} else {
return await this.executeFunction(
'getNodesByCountryCodeAndStatus',
'Failed to get nodes by country and status',
countryCode,
status
status,
pageSize,
pageNumber,
);
}
}

/**
* Get nodes by region and status
* @param regionCode Region code of nodes
* @param pageSize Number of maximum elements of returned
* @param pageNumber Page index. Index starts from 1
* @param status Status of nodes
*/
public async getNodesByRegionCode(
regionCode: string,
pageSize: BigNumberish,
pageNumber: BigNumberish,
status?: EnumStatus) {
if (status === undefined) {
return await this.executeFunction(
'getNodesByRegionCode',
'Failed to get nodes by region',
regionCode
regionCode,
pageSize,
pageNumber
);
} else {
return await this.executeFunction(
'getNodesByRegionCodeAndStatus',
'Failed to get nodes by region and status',
regionCode,
status
status,
pageSize,
pageNumber
);
}
}

/**
* Get nodes by status
* @param status Status of nodes
* @param pageSize Number of maximum elements of returned
* @param pageNumber Page index. Index starts from 1
*/
public async getNodesByStatus(
status: EnumStatus) {
status: EnumStatus,
pageSize: BigNumberish,
pageNumber: BigNumberish) {
return await this.executeFunction(
'getNodesByStatus',
'Failed to get nodes by status',
status
status,
pageSize,
pageNumber
);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/vda-node-client/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ describe("vda-node-client", () => {
const countries = [...new Set(counrtryList)];

for (let i = 0; i < countries.length; i++) {
const result = await blockchainApi.getNodesByCountryCode(countries[i]);
const result = await blockchainApi.getNodesByCountryCode(countries[i], 10, 1);
assert.ok(result.length > 0, "Return 1 or more nodes for registered country code");
}
})

it('getNodesByCountryCodeAndStatus',async () => {
const removingCountryCode = (DID_NODE_MAP.get(REMOVE_START_DIDS[0].address)).countryCode;
const result = await blockchainApi.getNodesByCountryCode(removingCountryCode, EnumStatus.removing);
const result = await blockchainApi.getNodesByCountryCode(removingCountryCode, 10, 1, EnumStatus.removing);
assert.ok(result.length > 0, "Return 1 or more removing nodes for registered country code");
})

Expand All @@ -239,25 +239,25 @@ describe("vda-node-client", () => {
const regions = [...new Set(regionList)];

for (let i = 0; i < regions.length; i++) {
const result = await blockchainApi.getNodesByRegionCode(regions[i]);
const result = await blockchainApi.getNodesByRegionCode(regions[i], 10, 1);
assert.ok(result.length > 0, "Return 1 or more nodes for registered region code");
}
})

it('getNodesByRegionCodeAndStatus',async () => {
const removingRegioinCode = (DID_NODE_MAP.get(REMOVE_START_DIDS[0].address)).regionCode;
const result = await blockchainApi.getNodesByRegionCode(removingRegioinCode, EnumStatus.removing);
const result = await blockchainApi.getNodesByRegionCode(removingRegioinCode, 10, 1, EnumStatus.removing);
assert.ok(result.length > 0, "Return 1 or more removing nodes for registered country code");
})

it("getNodesByStatus", async () => {
let result = await blockchainApi.getNodesByStatus(EnumStatus.active);
let result = await blockchainApi.getNodesByStatus(EnumStatus.active, 10, 1);
assert.ok(result.length > 0, "Return 1 or more active nodes");

result = await blockchainApi.getNodesByStatus(EnumStatus.removing);
result = await blockchainApi.getNodesByStatus(EnumStatus.removing, 10, 1);
assert.ok(result.length > 0, "Return 1 or more pending removal nodes");

result = await blockchainApi.getNodesByStatus(EnumStatus.removed);
result = await blockchainApi.getNodesByStatus(EnumStatus.removed, 10, 1);
assert.ok(result.length >= 0, "Return 0 or more active nodes");
})
})
Expand Down
5 changes: 5 additions & 0 deletions packages/vda-node-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-03-22 (v3.0.2)
-------------------

- Update the functions for `StorageNodeRegitry` contract

2024-03-15 (v3.0.0)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion packages/vda-node-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@verida/vda-node-manager",
"version": "3.0.1",
"version": "3.0.2",
"description": "Client to manage storage nodes from the blockchain",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions packages/vda-node-manager/src/blockchain/ownerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,20 @@ export class VeridaNodeOwnerApi extends VeridaNodeManager {
}

}

/**
* Start 2-step ownership transfer
* @param to New owenr address
*/
public async transferOwnership(to: string) {
if (this.readOnly || !this.config.signKey) {
throw new Error(`Unable to submit to blockchain. In read only mode.`)
}

const response = await this.vdaWeb3Client!.transferOwnership(to);

if (response.success !== true) {
throw new Error(`Failed to transfer ownership: ${response.reason}`);
}
}
}
Loading