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

How can I get the value of getFilterChanges, Please tell me how to use getFilterChanges and getFilterLogs #294

Closed
QingYanL opened this issue Mar 7, 2019 · 13 comments
Assignees
Labels
good first issue Good for newcomers question Further information is requested
Projects
Milestone

Comments

@QingYanL
Copy link
Member

QingYanL commented Mar 7, 2019

Description

In the same block getFilterChanges have value return but getFilterLogs have not return.

Steps to Reproduce

  1. rpc sendRawTransaction --code 0x608060405234801561001057600080fd5b503373ffffffffffffffffffffffffffffffffffffffff167f4f8cfde3439a1a302c21ca51eec26086efbfd940b8c0279889fc6bb6e73ecc6660405160405180910390a2610136806100636000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b1146100515780636d4ce63c1461007e575b600080fd5b34801561005d57600080fd5b5061007c600480360381019080803590602001909291905050506100a9565b005b34801561008a57600080fd5b50610093610101565b6040518082815260200191505060405180910390f35b806000819055503373ffffffffffffffffffffffffffffffffffffffff167ffd28ec3ec2555238d8ad6f9faf3e4cd10e574ce7e7ef28b73caa53f9512f65b9826040518082815260200191505060405180910390a250565b600080549050905600a165627a7a72305820cf7f3327f93c31df14de53a6b241db977f745ec600a5e7b78af619fc38e7e6150029 --private-key 0x5f0258a4778057a8a7d97809bd209055b2fbafa654ce7d31ec7191066b9225e6

output:
{ "id": 4, "jsonrpc": "2.0", "result": { "hash": "0x6357e35851cc54ba9fc446f18938f255eea2d74ca14f05b0a5c35ca9089d059f", "status": "OK" } }

  1. get topics

rpc getTransactionReceipt --hash 0x6357e35851cc54ba9fc446f18938f255eea2d74ca14f05b0a5c35ca9089d059f

output:
"topics": [ "0x4f8cfde3439a1a302c21ca51eec26086efbfd940b8c0279889fc6bb6e73ecc66", "0x0000000000000000000000004b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" ]

  1. get newFilter result: "0xf"
./env.sh curl -X POST --data '{"jsonrpc":"2.0","method":"newFilter","params":[{"topics":["0x4f8cfde3439a1a302c21ca51eec26086efbfd940b8c0279889fc6bb6e73ecc66"]}],"id":1}' 127.0.0.1:1337

key create

transfer --address 0xda81082a5a2b69f7f802f96c9a48616c507d47cd --private-key 0x5f0258a4778057a8a7d97809bd209055b2fbafa654ce7d31ec7191066b9225e6 --value 1000000000000000000000
  1. /env.sh curl -X POST --data '{"jsonrpc":"2.0","method":"getFilterChanges","params":["0xf"],"id":74}' 127.0.0.1:1337

start with a null value return , post again has output

{ "jsonrpc": "2.0", "id": 74, "result": [ "0x0e03c53bd78f842295f548539f72bde9f104ddf92e91ea1a2cd2a3d73e6fba53", "0x59f21942f94013becb10533ebea392d9ad9337112122df8e878c208489746764", "0xa370cfb36db5461288afac715db8b78b3d7e3331a66474608b004e82255ef4bf", "0x2b50a41e3e9e3d964fb1f8fc48bc3aa71c52ccfb968b02213f44a560d1edb541", "0x191f5201bc9810dce9407f2ff69efc20adbcba6345fc02347f585dfddd712f32", "0x616e312285a1d604a397806bf967926476bf3289b90d125cebb3518fe4ec4f1a", "0x8870bb49413600daaeb48db3417a63858892c982b9316a297d54b78f838e147a", "0xb001c716f8dc5dac0e20ed884d919401aef29558bb959ff3d346a2e6c1ca3a87", "0x480362e570b0ed1b433490bb5b3f4e1f01fae5758f6140bf66e5b3d67b97ecfd", "0x020839a5930459aa970794b5bca0fd3433b02a9270820524f098ac38ab150364", "0x3f56922891d0df5e2f4ec56f0541b9a512988e5f10d476879caf492841db5ba5", "0x07ab1b5a863835822f95aba02aa8718af9687e03e24343e4d11ab4d502d7d71e", "0x1af9c2cd590a1e0f6769a234fa21fff2693be3c3f98edde4364bce53adba9311", "0x48ce4fe4e5ddcce27eb2f8afde5bafa0e08bb9d53a7197b34421afa789d02c1f", "0xefcd69237c89f71fb8c8a5171095a9b837d0cf65625c5b670c6c69d82e7b0443", "0x5cfcf63c3a060e4481255bb341cad12afdfad51ee300cf57efb884b6a8ddf836" ] }
6. /env.sh curl -X POST --data '{"jsonrpc":"2.0","method":"getFilterLogs","params":["0xf"],"id":74}' 127.0.0.1:1337

output:
{ "jsonrpc": "2.0", "id": 74, "result": [] }

Expected behavior: [In the same block getFilterChanges and getFilterLogs have value return ]

Actual behavior: [In the same block getFilterChanges have value return but getFilterLogs have not return]

Reproduce how often: [every time]

Versions

develop

Additional Information

[I want to know how to use getFilterChanges and getFilterLogs , when is the value output, what result output , Thanks].

@boundless-forest
Copy link
Contributor

  • getFilterLogs 查询结果是根据 filter 能刷选到的所有 log
  • getFilterChanges 查询结果是根据 filter 刷选自前次 getFilterChanges 查询后的增量 log 变化

@kaikai1024
Copy link
Contributor

cause transfer doesn't have logs.
You need to send a tx that execute a contract.

More details can ask for @ouwenkg

@boundless-forest
Copy link
Contributor

Is it convenient to paster your test contract here?

@boundless-forest boundless-forest added question Further information is requested good first issue Good for newcomers labels Mar 7, 2019
@QingYanL
Copy link
Member Author

QingYanL commented Mar 7, 2019

Is it convenient to paster your test contract here?

I only have construction contract code:

0x608060405234801561001057600080fd5b503373ffffffffffffffffffffffffffffffffffffffff167f4f8cfde3439a1a302c21ca51eec26086efbfd940b8c0279889fc6bb6e73ecc6660405160405180910390a2610136806100636000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b1146100515780636d4ce63c1461007e575b600080fd5b34801561005d57600080fd5b5061007c600480360381019080803590602001909291905050506100a9565b005b34801561008a57600080fd5b50610093610101565b6040518082815260200191505060405180910390f35b806000819055503373ffffffffffffffffffffffffffffffffffffffff167ffd28ec3ec2555238d8ad6f9faf3e4cd10e574ce7e7ef28b73caa53f9512f65b9826040518082815260200191505060405180910390a250565b600080549050905600a165627a7a72305820cf7f3327f93c31df14de53a6b241db977f745ec600a5e7b78af619fc38e7e6150029

@boundless-forest
Copy link
Contributor

#297

@kaikai1024
Copy link
Contributor

Please check our [docs][https://docs.citahub.com/zh-CN/cita/rpc-guide/rpc#getfilterchanges].

@boundless-forest boundless-forest self-assigned this Mar 7, 2019
@kaikai1024 kaikai1024 added the bug Something isn't working label Mar 8, 2019
@kaikai1024 kaikai1024 added this to To do in v0.23.0 via automation Mar 8, 2019
@kaikai1024 kaikai1024 added this to the v1.0.0-alpha milestone Mar 13, 2019
@kaikai1024
Copy link
Contributor

What's the situation?

@boundless-forest
Copy link
Contributor

What's the situation?

Sorry, I haven't start yet. Always interupted.

@boundless-forest boundless-forest moved this from To do to In progress in v0.23.0 Mar 20, 2019
@boundless-forest
Copy link
Contributor

Testcases about the problem:

Testing getFilterChanges use newBlockFilter

Details steps:

Step 1: Create one newBlockFilter with curl tool. In this way, we could avoid sdk's potential problems.

curl -X POST --data '{"jsonrpc":"2.0","method":"newBlockFilter","params":[],"id":73}' 127.0.0.1:1337 | jq

Result:

{
  "jsonrpc": "2.0",
  "id": 73,
  "result": "0x8"
}

Step 2: Waiting several minites, and then invoke getFilterChanges with blockFilter id created in step 1.

curl -X POST --data '{"jsonrpc":"2.0","method":"getFilterChanges","params":["0x8"],"id":74}' 127.0.0.1:1337 | jq

Result:

{
  "jsonrpc": "2.0",
  "id": 74,
  "result": [
    "0xf755eba52d1b193c898631b3fac1f9ac5bf43db4ffa71e8a3e8dd69e870b0d4d",
    "0x9f2a3b2614a16656f938c2a1e4c90abf25d0cf346f33540cd5deb169b84870b8",
    "0x10b4c577a2ef3d56c9cda9fdc752805a57827ee2cd6eb908d7edd942feb710b3",
    "0x30bb6f0d3e0428f04a00f5b805868578dd3f43179ceceb4cef33813e98d6286b",
    "0x743dd21ffc8a54bf52e035f41c4878223d51c803a93994e0e26bc0334ba6e87c",
    "0xc1e0e5e5e9241a857bf9ba31b86fb48f11abb5f0e81db3b78cc9e0f42d55ed38",
    "0xfef3810c48e66a518226f8b203a19ca82f10dd823998c96ac48256dce6cd4197",
    "0xff353452acdb9a937074cb95537e2e9d5ecb63bd53bdfb08c26d9bf2bb6bafec",
    "0xb51018a99cfee95c2a4fad95d6fee2bf8fa59c7a8754e7d713d46d29810438c8",
    "0xc22cbdbc2c398695ed2d86e76e20ceecd52b441312ce66a8757aa76506f85dad",
    "0x9d9be1faa66d995ead6e33e213d5a4f12a61d4c76558ed43ce9bc4847e9c4b7f",
    "0x455434d4b05628a0b57210eeb261c18c6b99e13371a89fcee740280018e66356",
    "0x13cfd82008c86c4a953df468738a17239a9fcb434271cb3cf7b47054b67cb160",
    "0xec85e2b86c2f564dcbd425b7fc31c316abbf0eb7fa7bdca546d2a7a799661da6",
    "0xad971f4ca759b1c72e78e3d3ffdeda74a6bab042a3a48c413893edb8219fa3d6",
    "0x4cffd3a98d31679c42e9b8f022cf0ca99ca5373d04dbaa7e7d492e2ba91ec23f",
    "0x912e795abcd84eb0b67bf51f96dcbee65df5260f71ec211ec2fd5ad18785593c",
    "0x23e4799fe9884257e00bfd75f675f85762bf6cac227602fa20ab8e286e577adf",
    "0x59404d0717b37f0ecae0256b1db31aa65c20231819c27b3a06d61d2a91c4099b"
  ]
}

We can get what we wanted, that's OK.

Testing getFilterChanges use newFilter

In this test, we need deploy one contract firstly and then modify some valiable state. Following steps:

Step 1: Deploy one contract

pragma solidity ^0.4.24;

contract Rectangle {
    uint x;
    uint y;
    event logRectangle(uint indexed x, uint y);   // x is indexed, which means that it could be used as a topic. 

    function set(uint x1, uint y1) public {
        x = x1;
        y = y1;
        emit logRectangle(x, y);
    }

    function getX() view public returns (uint) {
        return x;
    }

    function getY() view public returns (uint) {
        return x;
    }
}

Code binary:

608060405234801561001057600080fd5b50610175806100206000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630b7f16651461005c5780631ab06ee5146100875780635197c7aa146100be575b600080fd5b34801561006857600080fd5b506100716100e9565b6040518082815260200191505060405180910390f35b34801561009357600080fd5b506100bc60048036038101908080359060200190929190803590602001909291905050506100f2565b005b3480156100ca57600080fd5b506100d3610140565b6040518082815260200191505060405180910390f35b60008054905090565b81600081905550806001819055506000547f659e343dc29d524186e032751cabee88f01780dc1927b2612e96c37faed6f21f6001546040518082815260200191505060405180910390a25050565b600080549050905600a165627a7a72305820e4e66c7f0365ad10ae7279cf9f3dcedb7677ca09a9a7a00047e10595dd699e5d0029

Function signatures:

======= test.sol:Rectangle =======
Function signatures: 
5197c7aa: getX()
0b7f1665: getY()
1ab06ee5: set(uint256,uint256)

All stuffs about contract listed above. Deploying it using cita-cli:

rpc sendRawTransaction --code 0x608060405234801561001057600080fd5b50610175806100206000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630b7f16651461005c5780631ab06ee5146100875780635197c7aa146100be575b600080fd5b34801561006857600080fd5b506100716100e9565b6040518082815260200191505060405180910390f35b34801561009357600080fd5b506100bc60048036038101908080359060200190929190803590602001909291905050506100f2565b005b3480156100ca57600080fd5b506100d3610140565b6040518082815260200191505060405180910390f35b60008054905090565b81600081905550806001819055506000547f659e343dc29d524186e032751cabee88f01780dc1927b2612e96c37faed6f21f6001546040518082815260200191505060405180910390a25050565b600080549050905600a165627a7a72305820e4e66c7f0365ad10ae7279cf9f3dcedb7677ca09a9a7a00047e10595dd699e5d0029 --private-key 0x5f0258a4778057a8a7d97809bd209055b2fbafa654ce7d31ec7191066b9225e6

Result:

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "blockHash": "0x1d3ded31133141e2d7f498ff0dbae17b6173f7bd7ca01c0c1cae855b00db013d",
    "blockNumber": "0x2d3",
    "contractAddress": "0xcf73525b380c5b706f35c1ff02aa798cc9950860",
    "cumulativeQuotaUsed": "0x1f2eb",
    "errorMessage": null,
    "logs": [
    ],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "quotaUsed": "0x1f2eb",
    "root": null,
    "transactionHash": "0x3d42db00750b816fab90215f3cc48afcb9bfceb2c38ae61bd9f6a7c0e183b734",
    "transactionIndex": "0x0"
  }
}

Step 2: Create one newFilter with curl tool.

curl -X POST --data '{"jsonrpc":"2.0","method":"newFilter","params":[{"topics":["0x659e343dc29d524186e032751cabee88f01780dc1927b2612e96c37faed6f21f"]}],"id":1}' 127.0.0.1:1337 | jq

Result:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0xc"
}

Step 3: Send transaction to modify variable

rpc sendRawTransaction --address 0xcf73525b380c5b706f35c1ff02aa798cc9950860 --code 0x1ab06ee500000000000000000000000000000000000000000000000000000000000000930000000000000000000000000000000000000000000000000000000000000420 --private-key 0x5f0258a4778057a8a7d97809bd209055b2fbafa654ce7d31ec7191066b9225e6

Step 4: Waiting several minites, and then invoke getFilterChanges with filter id created in step 2.

curl -X POST --data '{"jsonrpc":"2.0","method":"getFilterChanges","params":["0xc"],"id":74}' 127.0.0.1:1337 | jq

Result:

{
  "jsonrpc": "2.0",
  "id": 74,
  "result": [
    {
      "address": "0xcf73525b380c5b706f35c1ff02aa798cc9950860",
      "topics": [
        "0x659e343dc29d524186e032751cabee88f01780dc1927b2612e96c37faed6f21f",
        "0x0000000000000000000000000000000000000000000000000000000000000093"
      ],
      "data": "0x0000000000000000000000000000000000000000000000000000000000000420",
      "blockHash": "0xb4cdaf85423073fa8f39e10969d4bb1ec60d4799b0ea08cf73f4278d2200f47f",
      "blockNumber": "0x40b",
      "transactionHash": "0xcee4e5837577dfd3bfe8531aaaa05745e00def91bfb38332f915e019557d63ef",
      "transactionIndex": "0x0",
      "logIndex": "0x0",
      "transactionLogIndex": "0x0"
    }
  ]
}

It works ok.

Note: You must create your filter before modifying variable state, in other word, you cannot do step 3 ahead step 2.

@boundless-forest
Copy link
Contributor

@kaikai1024 @QingYanL

@kaikai1024
Copy link
Contributor

kaikai1024 commented Mar 21, 2019

You must create your filter before modifying variable state

yeah, of course, filter id watches the changes, so if you send a tx, how can get a changes?

so it's not a bug, right? maybe add some descriptions about it. @ouwenkg

@boundless-forest boundless-forest removed the bug Something isn't working label Mar 21, 2019
@kaikai1024
Copy link
Contributor

kaikai1024 commented Mar 21, 2019

cool.

btw, you have edited my comment...

@boundless-forest
Copy link
Contributor

Yeal, not a bug. I will update our docs later this afternoon. Sorry, my mistake.

v0.23.0 automation moved this from In progress to Done Mar 21, 2019
v0.23.0 automation moved this from Done to In progress Mar 21, 2019
v0.23.0 automation moved this from In progress to Done Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
No open projects
v0.23.0
  
Done
Development

No branches or pull requests

3 participants