-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from GuiGou12358/main
V0.0.1
- Loading branch information
Showing
7 changed files
with
86 additions
and
54 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
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 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,15 +1,13 @@ | ||
{ | ||
"dependencies": { | ||
"@polkadot/api": "^10.12.4", | ||
"@polkadot/api-contract": "^10.12.4", | ||
"@polkadot/types": "^10.12.4", | ||
"@phala/sdk": "^0.5.10", | ||
"@phala/sdk": "^0.6.0-beta.19", | ||
"node-fetch": "^3.3.2", | ||
"yargs": "^17.0.22", | ||
"@types/yargs": "^17.0.22", | ||
"node-fetch": "^2", | ||
"yargs": "^17.0.22" | ||
"tsx": "^4.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.6.11", | ||
"typescript": "^4.9.5" | ||
"typescript": "^5.4.4" | ||
} | ||
} |
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 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 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,44 +1,53 @@ | ||
import {ApiPromise, Keyring, WsProvider} from '@polkadot/api'; | ||
import {KeyringPair} from '@polkadot/keyring/types'; | ||
import {CertificateData, OnChainRegistry, PinkContractPromise, signCertificate} from '@phala/sdk' | ||
import { typeDefinitions } from '@polkadot/types' | ||
import { types } from "@phala/sdk"; | ||
import { | ||
OnChainRegistry, | ||
PinkContractPromise, | ||
getClient, | ||
getContract, | ||
} from '@phala/sdk' | ||
import {readFileSync} from 'fs'; | ||
import {config} from './config'; | ||
|
||
export let api : ApiPromise; | ||
|
||
export let alice : KeyringPair; | ||
export let aliceCertificate: CertificateData; | ||
export let client : OnChainRegistry; | ||
|
||
export let rafflePhatContract : PinkContractPromise; | ||
|
||
export async function initConnection(){ | ||
|
||
if (api){ | ||
if (client){ | ||
return; | ||
} | ||
|
||
api = await ApiPromise.create({ | ||
client = await getClient({ | ||
transport: config.phatContractRpc | ||
}); | ||
/* | ||
api = await ApiPromise.create(options({ | ||
provider: new WsProvider(config.phatContractRpc), | ||
noInitWarn: true, | ||
//types: { ...types, ...typeDefinitions } | ||
}); | ||
})); | ||
*/ | ||
|
||
const[chain, nodeName, nodeVersion] = await Promise.all([ | ||
api.rpc.system.chain(), | ||
api.rpc.system.name(), | ||
api.rpc.system.version() | ||
client.api.rpc.system.chain(), | ||
client.api.rpc.system.name(), | ||
client.api.rpc.system.version() | ||
]); | ||
console.log('You are connected to chain %s using %s v%s', chain, nodeName, nodeVersion); | ||
|
||
alice = new Keyring({ type: 'sr25519' }).addFromUri("//Alice") | ||
aliceCertificate = await signCertificate({ api, pair: alice }) | ||
const abi = readFileSync(config.rafflePhatContractMetadata, 'utf-8'); | ||
|
||
const phatRegistry = await OnChainRegistry.create(api); | ||
const contractKey = await phatRegistry.getContractKey(config.rafflePhatContractAddress) as string; | ||
//const phatRegistry = await OnChainRegistry.create(api); | ||
//const contractKey = await phatRegistry.getContractKey(config.rafflePhatContractAddress) as string; | ||
//rafflePhatContract = new PinkContractPromise(api, phatRegistry, abi, config.rafflePhatContractAddress, contractKey); | ||
|
||
const rafflePhatContractMetadata = readFileSync(config.rafflePhatContractMetadata); | ||
const abi = JSON.parse(JSON.stringify(rafflePhatContractMetadata.toString())) | ||
rafflePhatContract = new PinkContractPromise(api, phatRegistry, abi, config.rafflePhatContractAddress, contractKey); | ||
//const suri = '//Alice'; | ||
//const provider = await KeyringPairProvider.createFromSURI(client.api, suri); | ||
|
||
rafflePhatContract = await getContract({ | ||
client, | ||
contractId: config.rafflePhatContractAddress, | ||
abi, | ||
//provider, | ||
} | ||
) | ||
} |
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