how to pass custom field in json rpc call to stream

+1 vote
Hi , I created a stream with custom fields key1 and key2 .

multichain-cli chain2 create stream custom1 false {"\"key1\"":"\"value1\"","\"key2\"":"\"value2\"}
{"method":"create","params":["stream","custom1",false,{"key1":"value1","key2":"v
alue2"}],"id":1,"chain_name":"chain2"}

Now how do I pass text to this stream along with custom fields ? I am using multichain-node node js to pass data to stream which look like this

curl -X POST -H 'Content-Type: application/json' -i http://localhost:3000/publish1 --data '{"key":"kefdghh","data":"7888765","key1":"val1","key2":"val2"}'

 

But doesnot look like working fine.  Can I see custom fields in liststreamitems ?
asked Jan 23, 2018 by amar
to clarify it further liststreams returns
    {
        "name" : "custom1",
        "createtxid" : "f67799f024116771789a4bc370efddf41fd3e9992316cb276248c8a0
c758c76a",
        "streamref" : "98-265-30710",
        "open" : false,
        "details" : {
            "key1" : "value1",
            "key2" : "value2"
        },
        "subscribed" : true,
        "synchronized" : true,
        "items" : 3,
        "confirmed" : 3,
        "keys" : 2,
        "publishers" : 1
    }

Now how do I publish to this stream with custom fields ?
multichain-cli chain2 publish custom1 "hello w
orld" 48656C6C6F20576F726C64210A {"\"key1\"":"\"value1\"","\"key2\"":"\"value2\"}  -- not working

curl -X POST -H 'Content-Type: application/json' -i http://localhost:3000/publish1 --data '{"key1":"val1","key2":"val2","key":"key-field","data":"78887623"}'
-- working but dont see anywherre custom fields in posted items.

1 Answer

0 votes
There is no facility for custom fields on top of the payload of stream items. In MultiChain 1.x, each stream item contains a binary payload, so if you want to embed JSON or some other rich format inside it, you need to perform the serialization yourself. MultiChain 2.0 (alpha 1) supports JSON natively when creating stream items – please see the documentation here for how to use it: https://www.multichain.com/developers/multichain-2-0-preview-releases/
answered Jan 23, 2018 by MultiChain
If there is no facility for publishing custom fields on top of the payload, why to allow stream creation with custom fields ? There must be some reasoning behind this. kindly explain
Because when you create a stream, there is no payload for that event. Therefore we provide space for metadata. A stream item is designed for a payload, so there's nothing stopping you putting the metadata in the payload if you wish to.
...