How can i implement etherium like smartcontract in multichain

+3 votes

I know smart contract has 2 main feature.

  • It has to be stored on the blockchain and each node has that copy
  • Code has to be executed independently by every node

I can achieve the point one but I am unable to achieve point two.

Scenario

I have a scenario like this. I have a stream called products. on webapp when a user creates product, it calls backend api and backend  creates create product_id as key and product will be like {name:'product_name'} and then backend calls multichain raw apis  to save that product in products stream.

now whenever new product is saved in products stream my backend will execute particular code which exist in smartcontract stream. this code transfer few quantity of native asset to the user who created product. the reason I put the code in smartcontract stream so that anyone can see that code. but the execution of the code is still in our control which looks centralized opposed to the nature of blockchain.

 

can you please give me the idea of how can that code be executed by all the nodes in the network independently.

asked Nov 16, 2018 by anshuman

1 Answer

+2 votes
You could look into Smart Filters in MultiChain 2.0, but you would have to structure this slightly differently than a smart contract.

Essentially you would create a transaction filter to ensure that, every time an entry is added to the stream, a payment is made to the creator of that product, where the identity of this creator is embedded inside the stream item. This would enforce the rule as you described it.
answered Nov 19, 2018 by MultiChain
I want to allocate assets only after product is saved in stream and the block is mined. Is that possoble with the filters?
Yes, you could use inline metadata to tag the output containing the payment to the creator as an asset that can only be spent after it has a certain number of combinations.

Then, use a transaction filter which uses the getfiltertxinput callback to verify that, for any input tagged with this inline metadata, the confirmations field is sufficiently high.
...