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

Custom operation with pybitshares #308

Open
qualwebs opened this issue Apr 26, 2022 · 6 comments
Open

Custom operation with pybitshares #308

qualwebs opened this issue Apr 26, 2022 · 6 comments

Comments

@qualwebs
Copy link

qualwebs commented Apr 26, 2022

Hi @xeroc ,
So, just wanted to use the blockchain as DB and wanted to store custom user data like email, bio...
After some finding I found custom operation plugin but don't have any direction, How to use it?
I looked into the JS library but that also not support the custom operations.

Does this library supports the custom operations?

@qualwebs
Copy link
Author

qualwebs commented May 3, 2022

Hi @xeroc
Please help,

@xeroc
Copy link
Member

xeroc commented May 13, 2022

The custom_operation plugins seems to be very specific. It further has no API to query data from it. No idea how that was supposed to work, have no documentation for that either.

@abitmore
Copy link
Member

FWIW about documentation, there was some info in bitshares/bitshares-core#1926, and I just added more. I don't think it's very detailed though, but it is what we have now.

@xeroc
Copy link
Member

xeroc commented May 16, 2022

FWIW about documentation, there was some info in bitshares/bitshares-core#1926, and I just added more. I don't think it's very detailed though, but it is what we have now.

Thanks for the docs. I found that in the C++ codebase as well. The problem for pybitshares is that we have no way of querying the multiindex containers directly. And the objects in 7.0.x are easy to search (would need to iterate over all of them to find entries of a certain account).

For this plugin to become more powerful we'd need an API so we can query from external.

@abitmore
Copy link
Member

FWIW about documentation, there was some info in bitshares/bitshares-core#1926, and I just added more. I don't think it's very detailed though, but it is what we have now.

Thanks for the docs. I found that in the C++ codebase as well. The problem for pybitshares is that we have no way of querying the multiindex containers directly. And the objects in 7.0.x are easy to search (would need to iterate over all of them to find entries of a certain account).

For this plugin to become more powerful we'd need an API so we can query from external.

To find data, the get_storage_info API (with some doc, also pasted in the link above) should be enough for most use cases. E.G.

$ curl -d '{"id":1,"method":"call","params":["custom_operations","get_storage_info",["abit-test","cat1"]]}' https://testnet.xbts.io/ws;echo
{"id":1,"result":[{"id":"7.0.0","account":"1.2.3833","catalog":"cat1","key":"mykey","value":{"a":"b"}}]}

@litepresence
Copy link

litepresence commented Dec 17, 2022

class custom(GrapheneObject):
    def __init__(self, *args, **kwargs):
        if isArgsThisClass(self, args):
            self.data = args[0].data
        else:
            if len(args) == 1 and len(kwargs) == 0:
                kwargs = args[0]
            super().__init__(
                OrderedDict(
                    [
                        ("fee", Asset(kwargs["fee"])),
                        ("payer", ObjectId(kwargs["payer"], "account")),
                        (
                            "required_auths",
                            Set(ObjectId(kwargs["required_auths"], "account")),
                        ),
                        ("id", Uint16(kwargs["fee"])),
                        (
                            "data",
                            Map(
                                [
                                    [
                                        String(d[0]),
                                        String(d[1])
                                        if isinstance(d[1], str)
                                        else Set([String(i) for i in d[1]]),
                                    ]
                                    for d in kwargs["data"]
                                ]
                            ),
                        ),
                    ]
                )
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants