Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

How to query a mapping data structure in the smart contract without the drizzle-form? #27

Open
simibac opened this issue Mar 16, 2020 · 5 comments

Comments

@simibac
Copy link

simibac commented Mar 16, 2020

Let's assume we have the following smart contract:

contract EventFactory{
    uint public eventIndex;
    mapping (uint => Event) public events;
    // ....
}

When reading data from a mapping, I must pass an argument as the key of the mapping. How do I get access to this getter getContractData?

<template>
  <div>
    <h3>Events</h3>
    <p>Number of events: {{ eventIndex }}</p>
    <p>Event: {{ event }}</p>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  name: "EventList",
  computed: {
    ...mapGetters("contracts", ["getContractData"]),

    eventIndex() {
      const eventIndex = this.getContractData({
        contract: "EventFactory",
        method: "eventIndex"
      });
      return eventIndex;
    },
    event() {
      const event = this.getContractData({
        contract: "EventFactory",
        method: "events",
        // How to dynamically query an event?
    });
  },
  created() {
    this.$store.dispatch("drizzle/REGISTER_CONTRACT", {
      contractName: "EventFactory",
      method: "eventIndex",
      methodArgs: [] // No args required for this method
    });

    this.$store.dispatch("drizzle/REGISTER_CONTRACT", {
      contractName: "EventFactory",
      method: "events",
      methodArgs: [0] // How to store all the events in the store?
    });
  }
};
</script>

Note: I don't want to use the drizzle components as I want to be able to style them individually.

@Zaskoda
Copy link

Zaskoda commented Aug 20, 2020

I've been grinding on this same question for about 20 hours now. I feel like I'm taking crazy pills. I can see that the data gets cached but I can't figure out how I'm supposed to be juggling keys. Either I'm missing something for this library is missing something.

@JMundondo
Copy link

same issue

@JMundondo
Copy link

where can i find docsx for the drizzle-vue plugin

@rafalkoziel
Copy link

Anyone knows the answer? same issue here

@Zaskoda
Copy link

Zaskoda commented Feb 16, 2021

I ultimately gave up on the Drizzle-Vue plugin altogether. It seems that the implementation is incomplete. Even if the plugin had worked smoothly for my needs, this solution spins up two stores and attempts to keep them in sync. This is certainly less than ideal. I do not know of a circumstance where I would recommend this plugin to anyone.

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

No branches or pull requests

4 participants