Skip to content

Commit b95066c

Browse files
committed
initial commit
0 parents  commit b95066c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+892
-0
lines changed

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
test
3+
.idea
4+
test.js
5+
package-lock.json

Diff for: .npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
test
3+
.idea
4+
test.js

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### PIRI CHAIN API Package
2+
3+
---
4+
Piri Chain is Block Chain system that based on dPos (Delegated Proof of Stake) and has it own environment to create wallet and token, transactions, sending or storing data as a transaction, delegation.
5+
6+
This repo is created for base API call and returns with json format. Some functions may not exists in this repo cause of private usage on commercial account. Some functions are added after major updates or urgent minors not with fix.
7+
8+
---

Diff for: config/client.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const {create} = require("apisauce");
2+
3+
4+
const mainnet = 'https://core.pirichain.com/';
5+
const testnet = 'https://testnet.pirichain.com/';
6+
7+
const apiClient = create({
8+
baseURL:
9+
(typeof window !== "undefined" && typeof window.document !== "undefined") ?
10+
(localStorage.getItem('isMainnet') === 'true' || localStorage.getItem('isMainnet') === null ? mainnet : (
11+
localStorage.getItem("server") === null ? testnet : localStorage.getItem("server").replaceAll("\"", "")
12+
)) :
13+
(piriChainNetworkIsMainNet ? piriChainMainNetServer : piriChainTestNetServer)
14+
});
15+
16+
module.exports = {
17+
client: apiClient
18+
}

Diff for: index.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class pirichainAPI {
2+
Wallet = {};
3+
Token = {};
4+
Transaction = {};
5+
Block = {};
6+
Data = {};
7+
Utility = {};
8+
Delegation = {};
9+
BuyPiri = {};
10+
Stats = {};
11+
Scenario = {};
12+
13+
14+
constructor({
15+
isMainNet = true,
16+
testNetServer = 'https://testnet.pirichain.com',
17+
mainNetServer = 'https://core.pirichain.com'
18+
}) {
19+
global.piriChainNetworkIsMainNet = isMainNet;
20+
global.piriChainTestNetServer = testNetServer;
21+
global.piriChainMainNetServer = mainNetServer
22+
23+
this.Wallet = require('./src/wallet');
24+
this.Token = require('./src/token');
25+
this.Transaction = require('./src/transaction');
26+
this.Block = require('./src/block');
27+
this.Data = require('./src/data');
28+
this.Utility = require('./src/utility');
29+
this.Delegation = require('./src/delegation');
30+
this.BuyPiri = require('./src/buypiri');
31+
this.Stats = require('./src/stats');
32+
this.Scenario = require('./src/scenario');
33+
}
34+
35+
36+
}
37+
38+
module.exports = pirichainAPI;

Diff for: package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@piriblockchain/core",
3+
"version": "1.12.9",
4+
"dependencies": {
5+
"apisauce": "^2.1.5",
6+
"base58check": "^2.0.0",
7+
"bip39": "^3.1.0",
8+
"elliptic": "^6.5.4",
9+
"mongo-sanitize": "^1.1.0",
10+
"ripemd160": "^2.0.2",
11+
"sha256": "^0.2.0"
12+
},
13+
"main": "index.js",
14+
"directories": {},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"keywords": [],
19+
"author": "Musa TOTAN <[email protected]> (https://www.npmjs.com/~musatotan)",
20+
"license": "BSD-3-Clause",
21+
"description": "Piri Chain API package contains base commands for common usage.",
22+
"homepage": "https://github.com/musatotan/pirichain",
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/musatotan/pirichain.git"
26+
},
27+
"bugs": {
28+
"url": "https://github.com/musatotan/pirichain/issues",
29+
"email": "[email protected]"
30+
},
31+
"maintainers": [
32+
"Musa TOTAN",
33+
"Ömer ÇAKICI"
34+
]
35+
}

Diff for: src/block/getBlock.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {client} = require('../../config/client');
2+
3+
const endpoint = "/getBlock";
4+
5+
module.exports.getBlock = (blockNumber) => client.post(endpoint, {
6+
"blockNumber": blockNumber
7+
});

Diff for: src/block/getBlocks.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getBlocks";
4+
5+
module.exports.getBlocks = (skip, limit) => client.post(endpoint, {
6+
"skip": skip,
7+
"limit": limit
8+
});

Diff for: src/block/getBlocksDesc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getBlocksDesc";
4+
5+
module.exports.getBlocksDesc = (skip, limit) => client.post(endpoint, {
6+
"skip": skip,
7+
"limit": limit
8+
});

Diff for: src/block/getLastBlocks.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getLastBlocks";
4+
5+
module.exports.getLastBlocks = (limit) => client.post(endpoint, {
6+
"limit": limit
7+
});

Diff for: src/block/getOnlyBlocks.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getOnlyBlocks";
4+
5+
module.exports.getOnlyBlocks = (skip, limit) => client.post(endpoint, {
6+
"skip": skip,
7+
"limit": limit
8+
});

Diff for: src/block/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const {getBlock} = require('./getBlock');
2+
const {getBlocks} = require('./getBlocks');
3+
const {getBlocksDesc} = require('./getBlocksDesc');
4+
const {getOnlyBlocks} = require('./getOnlyBlocks');
5+
const {getLastBlocks} = require('./getLastBlocks');
6+
7+
module.exports = {
8+
getBlock: getBlock,
9+
getBlocks: getBlocks,
10+
getBlocksDesc: getBlocksDesc,
11+
getOnlyBlocks: getOnlyBlocks,
12+
getLastBlocks: getLastBlocks
13+
}

Diff for: src/buypiri/createAddressForBuyPiri.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/createAddressForBuyPiri";
4+
5+
module.exports.createAddressForBuyPiri = (type) => client.post(endpoint, {
6+
"type": type,
7+
});

Diff for: src/buypiri/getBalanceForBuyPiri.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getBalanceForBuyPiri";
4+
5+
module.exports.getBalanceForBuyPiri = (type, address, piriAddress) => client.post(endpoint, {
6+
"type": type,
7+
"address": address,
8+
"piriAddress": piriAddress
9+
});

Diff for: src/buypiri/getPiriPrice.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getPiriPrice";
4+
5+
module.exports.getPiriPrice = (type) => client.post(endpoint, {
6+
"type": type
7+
});

Diff for: src/buypiri/givemePiri.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/givemePiri";
4+
5+
module.exports.givemePiri = (address) => client.post(endpoint, {
6+
"address": address
7+
});

Diff for: src/buypiri/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const {createAddressForBuyPiri} = require('./createAddressForBuyPiri');
2+
const {getBalanceForBuyPiri} = require('./getBalanceForBuyPiri');
3+
const {getPiriPrice} = require('./getPiriPrice');
4+
const {givemePiri} = require("./givemePiri");
5+
6+
module.exports = {
7+
createAddressForBuyPiri: createAddressForBuyPiri,
8+
getBalanceForBuyPiri: getBalanceForBuyPiri,
9+
getPiriPrice: getPiriPrice,
10+
givemePiri: givemePiri
11+
}

Diff for: src/data/decrypt.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = '/decrypt';
4+
5+
module.exports.decrypt = (customID, privateKey, receiptPub) => client.post(endpoint, {
6+
'customID': customID,
7+
'privateKey': privateKey,
8+
"receiptPub": receiptPub
9+
});

Diff for: src/data/getAddressListByAsset.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getAddressListByAsset";
4+
5+
module.exports.getAddressListByAsset = (assetID, start, limit) => client.post(endpoint, {
6+
"assetID": assetID,
7+
"start": start,
8+
"limit": limit
9+
});

Diff for: src/data/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const {decrypt} = require('./decrypt');
2+
const {getAddressListByAsset} = require('./getAddressListByAsset');
3+
const {listData} = require('./listData');
4+
const {listDataByAddress} = require('./listDataByAddress');
5+
const {pushData} = require('./pushData');
6+
const {pushDataList} = require("./pushDataList");
7+
8+
module.exports = {
9+
decrypt: decrypt,
10+
getAddressListByAsset: getAddressListByAsset,
11+
listData: listData,
12+
listDataByAddress: listDataByAddress,
13+
pushData: pushData,
14+
pushDataList: pushDataList
15+
}

Diff for: src/data/listData.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/listData";
4+
5+
module.exports.listData = (limit, skip) => client.post(endpoint, {
6+
"limit": limit,
7+
"skip": skip
8+
});

Diff for: src/data/listDataByAddress.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/listDataByAddress";
4+
5+
module.exports.listDataByAddress = (address, limit, skip) => client.post(endpoint, {
6+
"address": address,
7+
"limit": limit,
8+
"skip": skip
9+
});

Diff for: src/data/pushData.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/pushData";
4+
5+
module.exports.pushData = (address, privateKey, to, indPubKey, key, value, enc) => client.post(endpoint, {
6+
"address": address,
7+
"privateKey": privateKey,
8+
"to": to,
9+
"indPubKey": indPubKey,
10+
"customData[]": JSON.stringify({ "key": key, "value": value, "enc": enc })
11+
});

Diff for: src/data/pushDataList.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/pushData";
4+
5+
module.exports.pushDataList = (address, privateKey, to, customData, indPubKey) => client.post(endpoint, {
6+
"address": address,
7+
"privateKey": privateKey,
8+
"to": to,
9+
"customData": customData,
10+
"indPubKey": indPubKey
11+
});

Diff for: src/delegation/checkDeputy.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/checkDeputy";
4+
5+
module.exports.checkDeputy = (address) => client.post(endpoint, {
6+
"address": address
7+
});

Diff for: src/delegation/freezeCoin.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/freezeCoin";
4+
5+
module.exports.freezeCoin = (delegationAddress, delegationPrivateKey, duptyAddress, amount) => client.post(endpoint, {
6+
"delegationAddress": delegationAddress,
7+
"delegationPrivateKey": delegationPrivateKey,
8+
"duptyAddress": duptyAddress,
9+
"amount": amount
10+
});

Diff for: src/delegation/getMyRewardQuantity.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/getMyRewardQuantity";
4+
5+
module.exports.getMyRewardQuantity = (base58, privateKey) => client.post(endpoint, {
6+
"base58": base58,
7+
"privateKey": privateKey
8+
});

Diff for: src/delegation/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const {checkDeputy} = require('./checkDeputy');
2+
const {freezeCoin} = require('./freezeCoin');
3+
const {joinAsDeputy} = require('./joinAsDeputy');
4+
const {listDeputies} = require('./listDeputies');
5+
const {listMyDelegation} = require('./listMyDelegation');
6+
const {unFreezeCoin} = require('./unFreezeCoin');
7+
const {listDelegationTopN} = require('./listDelegationTopN');
8+
const {getMyRewardQuantity} = require("./getMyRewardQuantity");
9+
10+
module.exports = {
11+
checkDeputy: checkDeputy,
12+
freezeCoin: freezeCoin,
13+
joinAsDeputy: joinAsDeputy,
14+
listDeputies: listDeputies,
15+
listMyDelegation: listMyDelegation,
16+
unFreezeCoin: unFreezeCoin,
17+
listDelegationTopN: listDelegationTopN,
18+
getMyRewardQuantity: getMyRewardQuantity
19+
}

Diff for: src/delegation/joinAsDeputy.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/joinAsDeputy";
4+
5+
module.exports.joinAsDeputy = (address, privateKey, alias, website) => client.post(endpoint, {
6+
"address": address,
7+
"privateKey": privateKey,
8+
"alias": alias,
9+
"website": website
10+
});

Diff for: src/delegation/listDelegationTopN.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/listDelegationTopN";
4+
5+
module.exports.listDelegationTopN = () => client.post(endpoint);

Diff for: src/delegation/listDeputies.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/listDeputies";
4+
5+
module.exports.listDeputies = () => client.post(endpoint);

Diff for: src/delegation/listMyDelegation.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const {client} = require('../../config/client')
2+
3+
const endpoint = "/listMyDelegation";
4+
5+
module.exports.listMyDelegation = (delegationAddress, delegationPrivateKey) => client.post(endpoint, {
6+
"delegationAddress": delegationAddress,
7+
"delegationPrivateKey": delegationPrivateKey,
8+
});

0 commit comments

Comments
 (0)