python-bitshares
python-bitshares copied to clipboard
Custom operation with pybitshares
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?
Hi @xeroc Please help,
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.
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.
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.
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"}}]}
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"]
]
),
),
]
)
)