Coder Social home page Coder Social logo

isabella232 / origin-subgraph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from graphprotocol/origin-subgraph

0.0 0.0 0.0 321 KB

Origin is a protocol for creating peer-to-peer marketplaces using the Ethereum blockchain and IPFS.

TypeScript 100.00%

origin-subgraph's Introduction

Origin-subgraph

Origin is a protocol for creating peer-to-peer marketplaces using the Ethereum blockchain and IPFS.

Events and Contracts

The Origin smart contracts are set up so that the majority of the events are emitted from a single address. The Solidity file that has these events is Marketplace.sol.

All events in this subgraph are tracked.

This subgraph can be used for Origin on the mainnet, and all testnets. In order to run it for a testnet, the subgraph.yaml file will need to have the contract addresses changed to point to the correct address for each respective network.

The subgraph takes less than 10 minutes to sync.

Note - This subgraph currently only ipfs cats up to block 7,100,000 for the mappings. This is because the ipfs node running alongside The Graph Node get hung up on searching for the file for too long, so they are pinned up to there. The subgraph should be able to connect to the origin ipfs node via swarm, but we are waiting to coordinate that. You can access all the origin IPFS files through https at https://ipfs.originprotocol.com/ipfs/.

Brief Description of The Graph Node Setup

A Graph Node can run multiple subgraphs. The subgraph ingests event data by calling to Infura through http. It can also connect to any geth node or parity node that accepts RPC calls. Fast synced geth nodes work. To use parity, the --no-warp flag must be used. Setting up a local Ethereum node is more reliable and faster, but Infura is the easiest way to get started.

This subgraph has three types of files which tell the Graph Node to ingest events from specific contracts. They are:

  • The subgraph manifest (subgraph.yaml)
  • A GraphQL schema (schema.graphql)
  • Mapping scripts (marketplace.ts)

This repository has these files created and ready to compile, so a user can start this subgraph on their own. The only thing that needs to be edited is the contract addresses in the subgraph.yaml file to change between mainnet and testnets.

We have provided a quick guide on how to start up the origin-subgraph graph node below. If these steps aren't descriptive enough, the getting started guide has in depth details on running a subgraph.

Steps to Deploying The Origin-Subgraph Locally

  1. Install IPFS and run ipfs init followed by ipfs daemon
  2. Install PostgreSQL and run initdb -D .postgres followed by pg_ctl -D .postgres start and createdb graph-node-mainnet (note this db name is used in the commands below for the mainnet examples)
  3. If using Ubuntu, you may need to install additional packages: sudo apt-get install -y clang libpq-dev libssl-dev pkg-config
  4. Clone this repository, and run the following:
    • yarn
    • yarn codegen
  5. Clone https://github.com/graphprotocol/graph-node from master and cargo build (this might take a while)
  6. a) Now that all the dependencies are running, you can run the following command to connect to Infura Mainnet (it may take a few minutes for Rust to compile). PASSWORD might be optional, it depends on your postrgres setup:
  cargo run -p graph-node --release -- \
  --postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-mainnet \
  --ipfs 127.0.0.1:5001 \
  --ethereum-rpc mainnet-infura:https://mainnet.infura.io --debug
  1. b) Or Mainnet with a Local Ethereum node. This is very common if you are working with brand new contracts, and you have deployed them to a testnet environment like ganache (note that ganache commonly uses port 9545 rather than 8545):
  cargo run -p graph-node --release -- \
  --postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-mainnet \
  --ipfs 127.0.0.1:5001 \
  --ethereum-rpc mainnet-local:http://127.0.0.1:8545 
  1. c) Or Infura Rinkeby (NOTE: Infura testnets are not reliable right now, we get inconsistent results returned. If Rinkeby data is needed, it is suggested to run your own Rinkeby node)
    cargo run -p graph-node --release --   \
    --postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-testnet \
    --ipfs 127.0.0.1:5001 \
    --ethereum-rpc rinkeby-infura:https://rinkeby.infura.io 

  1. Now create the subgraph locally on The Graph Node with yarn create-local.

  2. Next deploy the Origin subgraph to The Graph Node with yarn deploy --debug. You should see a lot of blocks being skipped in the graph-node terminal, and then it will start ingesting events from the moment the contracts were uploaded to the network.

Now that you have subgraph is running you may open a Graphiql browser at 127.0.0.1:8000 and get started with querying.

Viewing the Subgraph on the Graph Hosted Service

This subgraph has already been deploy to the hosted service, and you can see it under on The Graph Explorer. To understand how deploying to the hosted service works, check out the Deploying Instructions in the official documentation. The most important part of deploying to the hosted service is ensuring that the npm script for deploy is updated to the correct name that you want to deploy with.

Getting started with querying

Below are a few ways to show how to query the origin-subgraph for data.

Querying all User Information

The query below shows all the information for one user. This would represent what is on the users profile page in the Origin Dapp. There are many other filtering options that can be used, just check out the querying api.

{
  user(id: "0x6c6e93874216112ef12a0d04e2679ecc6c3625cc"){
    id
    attestations{
      id
      schemaId
      userAddress
      issuerURL
      issueDate
      issuerName
      issuerAddress
      method
      verified
      signature
      signatureVersion
      base58Hash    
    }
    listings{
      id
      blockNumber
      seller
      depositManager
      deposit
      status
      offers{
        id
        listingID
        blockNumber
        value
        commission
        refund
        buyer
        affiliate
        arbitrator
        finalizes
        status
        base58Hash
        reviews{
          id
          blockNumber
          schemaId
          rating
          text
          offerID
        }
        disputer
        ruling
        schemaId
        listingType
        unitsPurchased
        price
        currency
        commissionPrice
        commissionCurrency
        ipfsCatSuccess
        offerExtraData{
          id
          offerID
          sender
          bytesHash
          base58Hash
        }
        extraDataCount
      }
      extraDataCount
      base58Hash
      price
      currency
      commissionAmount
      commissionCurrency
      commissionPerUnit
      commissionPerUnitCurrency
      schemaId
      listingType
      category
      subCategory
      language
      title
      description
      unitsTotal
      dappSchemaId
      media{
        id
        url
        contentType
        listingID
      }
      ipfsCatSuccess
    }
    profile{
      id
      firstName
      lastName
      description
      avatar
      schemaId
      base58Hash
    }
    schemaId
    ipfsCatSuccess
  }
}

Query all Information on a Listing

This query will return all data related to a listing, which would be used for viewing a listing in the Origin Dapp.

{
  listing(id: "713") {
    id
    blockNumber
    seller
    depositManager
    deposit
    status
    offers {
      id
      listingID
      blockNumber
      value
      commission
      refund
      buyer
      affiliate
      arbitrator
      finalizes
      status
      base58Hash
      reviews {
        id
        blockNumber
        schemaId
        rating
        text
        offerID
      }
      disputer
      ruling
      schemaId
      listingType
      unitsPurchased
      price
      currency
      commissionPrice
      commissionCurrency
      ipfsCatSuccess
      offerExtraData {
        id
        offerID
        sender
        bytesHash
        base58Hash
      }
      extraDataCount
    }
  }
}

origin-subgraph's People

Contributors

davekaj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.