bdcontract-sdk-javascript/test-node/index.js

104 lines
3.9 KiB
JavaScript
Raw Permalink Normal View History

2023-03-14 17:15:57 +00:00
const bdcontract = require('@bdcontract/sdk')
// const sm2 = require('sm-crypto')
// import { sm2 } from 'sm-crypto'
async function main() {
// const url = 'http://localhost:21030/SCIDE'
const url = 'http://39.104.201.40:18010/SCIDE'
// const url = 'http://39.104.201.40:18010/NodeCenter'
// const url = 'http://021.node.internetapi.cn:18060/NodeCenter'
// const url = 'http://localhost/8080/api/sse'
// eslint-disable-next-line no-undef
const sm2Key = {
publicKey:
'04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27',
privateKey:
'd675782acf011dbc01a73c7967ccff9564486f7c3a9f5d5de151caffaa18936',
}
// const keyPair = sm2.generateKeyPairHex()
// const url1 = 'http://023.node.internetapi.cn:18010/SCIDE/SCManager'
// const url1 = 'http://023.node.internetapi.cn:18010/SCIDE/SCManager?action=applyNodeRole&role=ContractProvider&pubKey=04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27&sign=3046022100d186df39542f44deb08ca9a6a33ea4c0eef4222c3d0a9821e836a231daa615fa022100d89b202b3bb44c8caf98b3c415c62359eab2607c391ad04ba39034a550a78db3'
// const res1 = await fetch(url1)
// console.log(res1)
// const res2 = await fetch(url1)
// console.log(res2)
// eslint-disable-next-line no-undef
const client = new bdcontract.HttpClient(url, sm2Key, { timeout: 20000 })
try {
// const result = await client.executeContract(
// 'ControlProxy',
// 'setName',
// { name: 'df' },
// 'POST',
// true,
// )
// const result = await client.updateConfig('dataChain', 'ddsjkdsf')
// const result = await client.resetNodeManager()
// const result = await client.applyNodeRole('ContractProvider')
// const result = await client.loadNodeConfig()
// const result = await client.configContract({
// nodeName: 'test',
// bdledgerAddr: 'bdledger:2401',
// masterAddr: 'localhost:21030',
// contractCenterAddr: 'localhost:21040',
// // 配置中心节点时使用
// LHSProxyAddress: 'http://localhost:21041',
// })
// console.log(result, 'res1')
const result = await client.executeContract(
'ControlProxy',
'getDoList',
1,
true,
)
console.log(result, 'res1')
} catch (e) {
console.log('error: ', e.message)
}
// const res2 = await client.applyNodeRole('ContractInstanceManager')
// console.log(res2.data, 'res2')
// const res2 = await client.authNodeManager(
// true,
// '0430276215ff414e0047a532d4dea32048ad4ec60a729ce8e4248c98889d244c3b27b9549e5cb664ce324e2acac4a81590321f4196ca159cb577e06a3eb553ce6a',
// )
// // const res3 = await client.applyRole('NodeManager')
// console.log(res2, 'res2res2res2res2res2res2res2res2res2res2res2')
// const res3 = await client.applyNodeRole(
// '0430276215ff414e0047a532d4dea32048ad4ec60a729ce8e4248c98889d244c3b27b9549e5cb664ce324e2acac4a81590321f4196ca159cb577e06a3eb553ce6a',
// 'ContractInstanceManager',
// )
// console.log(res3, 'res33333333333333333333333333333333')
// // console.log(res1.data, 'data')
// const res1 = await client.authNodeRole(
// true,
// '0430276215ff414e0047a532d4dea32048ad4ec60a729ce8e4248c98889d244c3b27b9549e5cb664ce324e2acac4a81590321f4196ca159cb577e06a3eb553ce6a',
// )
// console.log(res1, 'res11111111111111111111111111111111')
// console.log(res1.data, 'data')
// const res1 = await client.applyRole('ContractProvider')
// console.log(res1, 'res')
// console.log(res1.data, 'data')
// let i = 0
// for (i = 0; i < 3000000000; i++) {
// a = i + 1
// if (a > 100000000000000) {
// console.log('b')
// }
// }
// setTimeout(async ()=> {
// const client2 = new bdcontract.HttpClient(url, sm2Key)
// const res2 = await client.applyNodeRole('ContractInstanceManager')
// console.log(res2)
// }, 1)
}
void main().then(console.log)