Skip to content

Commit

Permalink
Merge pull request #203 from AElfProject/feature/withCredentials
Browse files Browse the repository at this point in the history
feat: credentials
  • Loading branch information
hzz780 authored Nov 23, 2024
2 parents a9096fd + 150b395 commit 926c820
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 339 deletions.
2 changes: 1 addition & 1 deletion build/webpack.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const nodeConfig = {
mode: 'production',
output: {
path: OUTPUT_PATH,
filename: 'aelf.cjs.js',
filename: 'aelf.cjs',
library: {
type: 'commonjs2'
},
Expand Down
6 changes: 5 additions & 1 deletion examples/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
console.log(walletGotByMn);
// link to Blockchain
const aelf = new AElf(new AElf.providers.HttpProvider(
'https://tdvw-test-node.aelf.io/'
'https://tdvw-test-node.aelf.io/',
// 8000,
// {
// credentials: 'include'
// }
));

if (!aelf.isConnected()) {
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion examples/node/index.js → examples/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const defaultPrivateKey = 'bdb3b39ef4cd18c2697a920eb6d9e8c3cf1a930570beb37d04fb5
// const walletCreatedByMethod = Wallet.createNewWallet();
const wallet = Wallet.getWalletByPrivateKey(defaultPrivateKey);
// link to Blockchain
const aelf = new AElf(new AElf.providers.HttpProvider('https://tdvw-test-node.aelf.io/'));
const aelf = new AElf(
new AElf.providers.HttpProvider('https://tdvw-test-node.aelf.io/', 8000, {
// cookie: '123',
credential: 'omit'
})
);

if (!aelf.isConnected()) {
console.log('Blockchain Node is not running.');
Expand Down
File renamed without changes.
154 changes: 88 additions & 66 deletions examples/node/random/index.js → examples/node/random/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
const AElf = require('../../../dist/aelf.cjs');

const Wallet = AElf.wallet;
const {
sha256
} = AElf.utils;
const { sha256 } = AElf.utils;

// address: 2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX
const defaultPrivateKey = 'bdb3b39ef4cd18c2697a920eb6d9e8c3cf1a930570beb37d04fb52400092c42b';
Expand Down Expand Up @@ -41,29 +39,35 @@ const lotteryContract = aelf.chain.contractAt(lotteryContractAddress, wallet, {
sync: true
});

const initialize = lotteryContract.Initialize({
sponsor: '2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX',
startPeriod: 0,
startTimestamp: {
seconds: (new Date()).getTime() / 1000
const initialize = lotteryContract.Initialize(
{
sponsor: '2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX',
startPeriod: 0,
startTimestamp: {
seconds: new Date().getTime() / 1000
},
tokenSymbol: 'ELF',
ready: true
},
tokenSymbol: 'ELF',
ready: true,
}, {
sync: true
});
{
sync: true
}
);

console.log('initialInfo', initialize);

try {
"Error": "\nAElf.Sdk.CSharp.AssertionException: No record now.\n'
let records = lotteryContract.GetRecord.call({
offset: 0,
limit: 10
}, {
sync: true
});
} catch(e) {
// "Error": "\nAElf.Sdk.CSharp.AssertionException: No record now.\n'
let records = lotteryContract.GetRecord.call(
{
offset: 0,
limit: 10
},
{
sync: true
}
);
} catch (e) {
// 错误返回不合适
// { Code: '20008',
// Message: 'Invalid transaction information',
Expand All @@ -74,33 +78,42 @@ try {

// init: bf1fca5468599d2e04b24848fb498e2976fa6c976cfcb31540409df40bddd01c
// noRecord: bc196d94ed41890886534ba824a325728eeb5f818b328db3079a94b3ea79d555
lotteryContract.GetRecord({
offset: 0,
limit: 10
}, {
sync: true
});
lotteryContract.GetRecord(
{
offset: 0,
limit: 10
},
{
sync: true
}
);

var record = lotteryContract.GetRecord.call({
offset: 0,
limit: 10
}, {
sync: true
});
var record = lotteryContract.GetRecord.call(
{
offset: 0,
limit: 10
},
{
sync: true
}
);
console.log(JSON.stringify(record));

// 开启新的一轮
let peroid = lotteryContract.NewPeriod({
periodNumber: 1,
// bc6672baf5e4984f4f1e0fbe698d170e07ebe8a29320cce17a899495dcd391d0
randomNumberToken: '7e55bbc211171e48131d8ff7c8c2b38def7923ab717011066658b90219c1cae6' // 0
}, {
sync: true
});
let peroid = lotteryContract.NewPeriod(
{
periodNumber: 1,
// bc6672baf5e4984f4f1e0fbe698d170e07ebe8a29320cce17a899495dcd391d0
randomNumberToken: '7e55bbc211171e48131d8ff7c8c2b38def7923ab717011066658b90219c1cae6' // 0
},
{
sync: true
}
);

lotteryContract.GetLuckyNumber({sync: true});
lotteryContract.GetLuckyNumber({ sync: true });

lotteryContract.GetState.call({sync: true});
lotteryContract.GetState.call({ sync: true });

// message Lotteries {
// repeated Lottery lottery = 1;
Expand All @@ -123,33 +136,42 @@ for (let i = 0; i <= 9; i++) {
});
}

lotteryContract.Bet({
salerAddress: '2C2Acy4saYsnkRYEf54VawvmvUTAvrrWHKbLSwLg33b26woJVu',
proportionSale: 5,
proportionBonus: 5,
targetPeriod: 0,
senderAddress: '2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX',
lottery
}, {sync: true});

lotteryContract.Bet({
salerAddress: '2C2Acy4saYsnkRYEf54VawvmvUTAvrrWHKbLSwLg33b26woJVu',
proportionSale: 5,
proportionBonus: 5,
targetPeriod: 1,
senderAddress: '2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX',
lottery: [
{type: 1, value: [0, 0, 0, 0, 3]},
{type: 1, value: [0, 0, 0, 0, 4]},
{type: 1, value: [0, 0, 0, 0, 5]},
]
}, {sync: true});
lotteryContract.Bet(
{
salerAddress: '2C2Acy4saYsnkRYEf54VawvmvUTAvrrWHKbLSwLg33b26woJVu',
proportionSale: 5,
proportionBonus: 5,
targetPeriod: 0,
senderAddress: '2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX',
lottery
},
{ sync: true }
);

lotteryContract.Bet(
{
salerAddress: '2C2Acy4saYsnkRYEf54VawvmvUTAvrrWHKbLSwLg33b26woJVu',
proportionSale: 5,
proportionBonus: 5,
targetPeriod: 1,
senderAddress: '2hxkDg6Pd2d4yU1A16PTZVMMrEDYEPR8oQojMDwWdax5LsBaxX',
lottery: [
{ type: 1, value: [0, 0, 0, 0, 3] },
{ type: 1, value: [0, 0, 0, 0, 4] },
{ type: 1, value: [0, 0, 0, 0, 5] }
]
},
{ sync: true }
);

lotteryContract.TakeReward('a24fec480944c16f0ed250cb3412e2b27312afc59adad6941adb20eb08b1a3c9', {
sync: true
});

console.log('tx', aelf.chain.getTxResult('4c12bd187803fa1b63ac5794f614496154454725aa6c6747c890cdab39708e02', {
sync: true
}));
console.log(
'tx',
aelf.chain.getTxResult('4c12bd187803fa1b63ac5794f614496154454725aa6c6747c890cdab39708e02', {
sync: true
})
);
console.log('RandomToken', RandomToken);
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 926c820

Please sign in to comment.