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/multi transaction #197

Merged
merged 17 commits into from
Oct 16, 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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"extends": ["eslint-config-airbnb-base"],
"globals": {},
"rules": {
"function-paren-newline": "off",
"no-console": ["warn"],
"no-useless-escape": 0,
"no-empty": 0,
Expand All @@ -29,7 +30,7 @@
"no-underscore-dangle": "off",
"no-bitwise": "off",
"no-mixed-operators": "off",
"max-len": ["error", { "code": 120 , "ignoreComments": true}],
"max-len": ["error", { "code": 120, "ignoreComments": true }],
"class-methods-use-this": "off",
"no-plusplus": "off",
"implicit-arrow-linebreak": "off",
Expand Down
92 changes: 92 additions & 0 deletions examples/browser/multiTransaction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html>

<head>
<title>Hello AElf</title>
</head>

<body>
<p>Hello AElf.</p>

<script type="text/javascript" src="../../dist/aelf.umd.js"></script>
<script type="text/javascript">
const AElf = window.AElf;
const Wallet = AElf.wallet;
const sha256 = AElf.utils.sha256;
const wallet = AElf.wallet.getWalletByPrivateKey('943df6d39fd1e1cc6ae9813e54f7b9988cf952814f9c31e37744b52594cb4096');
// link to Blockchain
const aelf = new AElf(
new AElf.providers.HttpProvider("https://explorer-test.aelf.io/chain")
);
// the contract you want to query
const tokenContractName = "AElf.ContractNames.Token";
aelf.chain
.getChainStatus()
.then((info) => {
const {
// directly accessible information
GenesisContractAddress,
} = info;
console.log(GenesisContractAddress,"GenesisContractAddress===");
aelf.chain
.contractAt(GenesisContractAddress,wallet)
.then((zeroC) => {
// return contract's address which you query by contract's name
return zeroC.GetContractAddressByName.call(
sha256(tokenContractName)
);
})
.then((tokenContractAddress) => {
console.log("GetTokenInfo",tokenContractAddress);
// return contract's instance and you can call the methods on this instance
return aelf.chain.contractAt(tokenContractAddress,wallet,{
// refBlockNumberStrategy: {
// 9992731: -8,
// 1931928: -8
// },
multi: {
9992731: {
chainUrl: 'https://aelf-test-node.aelf.io/',
contractAddress: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE'
},
1931928: {
chainUrl: 'https://tdvw-test-node.aelf.io/',
contractAddress: 'ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx'
}
},
gatewayUrl: 'https://gateway-test.aelf.io'
});
})
.then(async (tokenContract) => {
console.log(tokenContract,'tokenContract')
const result = await tokenContract.sendMultiTransactionToGateway({
9992731: {
method: 'Transfer',
params: {
symbol: 'ELF',
amount: '100000000',
to: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk'
}
},
1931928: {
method: 'Transfer',// or any other method, no need to be same as main chain
params: {
symbol: 'ELF',
amount: '100000000',
to: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk'
}
}
})
return result;
})
.then((res) => {
console.log(res,'multiTransaction');
});
})
.catch((err) => {
console.error(err,"error");
});
</script>
</body>

</html>
474 changes: 251 additions & 223 deletions jest-report.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions jest.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ module.exports = {

// The glob patterns Jest uses to detect test files
testMatch: [
// '**/test/unit/chain/index.test.js'
// '**/test/unit/**/multiTransaction.test.js'
// '**/test/unit/**/contractMultiTransaction.test.js'
'**/test/unit/**/?(*.)+(test).[jt]s?(x)',
'**/test/unit/util/httpProvider.browser-test.js'
// "**/?(*.)+(spec|test).[tj]s?(x)"
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "aelf-sdk",
"version": "3.4.15",
"version": "3.4.16",
"description": "aelf-sdk js library",
"main": "dist/aelf.cjs.js",
"browser": "dist/aelf.umd.js",
"unpkg": "dist/aelf.umd.js",
"jsdelivr": "dist/aelf.umd.js",
"scripts": {
"build": "npm run clean && npm run build:browser && npm run build:node",
"build": "npm run clean && npm run build:browser && npm run build:node && npm run copy-ts",
"build:browser": "cross-env RUNTIME_ENV=browser webpack --progress --color --config ./build/webpack.browser.js",
"build:node": "cross-env RUNTIME_ENV=node webpack --progress --color --config ./build/webpack.node.js",
"analyze:node": "npm run clean && cross-env RUNTIME_ENV=node webpack --config ./build/webpack.analyze.js",
Expand All @@ -25,7 +25,8 @@
"test:node:watch": "jest --config=jest.node.config.js --watch",
"test:coverage": "jest --config=jest.browser.config.js --coverage",
"test:coverageNode": "jest --config=jest.node.config.js --coverage",
"prepare": "husky install"
"prepare": "husky install",
"copy-ts": "cpx \"types/**/*.ts\" dist/"
},
"keywords": [
"aelf-web3"
Expand Down Expand Up @@ -107,6 +108,7 @@
"chalk": "^4.1.2",
"commitizen": "^4.3.0",
"core-js": "^3.30.1",
"cpx": "^1.5.0",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.0.2",
"eslint": "^8.39.0",
Expand Down
8 changes: 8 additions & 0 deletions proto/aelf/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ message Transaction {
// the parameter that were given. It also contains the reference block number and prefix.
bytes signature = 10000;
}
message TransactionAndChainId {
Transaction transaction = 1;
int32 chain_id = 2;
}

message MultiTransaction {
repeated TransactionAndChainId transactions = 1;
bytes signature = 10000;
}
message StatePath {
// The partial path of the state path.
repeated string parts = 1;
Expand Down
Loading
Loading