python-bitshares icon indicating copy to clipboard operation
python-bitshares copied to clipboard

Custom operation with pybitshares

Open qualwebs opened this issue 2 years ago • 6 comments

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 avatar Apr 26 '22 12:04 qualwebs

Hi @xeroc Please help,

qualwebs avatar May 03 '22 11:05 qualwebs

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.

xeroc avatar May 13 '22 10:05 xeroc

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

abitmore avatar May 13 '22 19:05 abitmore

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.

xeroc avatar May 16 '22 06:05 xeroc

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"}}]}

abitmore avatar May 16 '22 12:05 abitmore

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"]
                                ]
                            ),
                        ),
                    ]
                )
            )

litepresence avatar Dec 17 '22 17:12 litepresence