Skip to content

Instantly share code, notes, and snippets.

@shnitish
Created January 13, 2021 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shnitish/2ca0bde014d13748ec1eba210612a585 to your computer and use it in GitHub Desktop.
Save shnitish/2ca0bde014d13748ec1eba210612a585 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.26+commit.4563c3fc.js&optimize=true&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.4.18;
contract Trade
{
address owner_address;
address buyer_address;
// constructor to set the owner of the contract
constructor (address buyer_add) public {
owner_address = msg.sender;
buyer_address = buyer_add;
}
// structure of the buyer
struct Buyer
{
address addr;
string name;
bool init;
}
// structure of the current shipment
struct Shipment
{
address courier;
uint price;
uint payment;
address payer;
uint date;
uint delivery_date;
bool init;
}
// structure of a particular order
struct Order
{
string product;
uint quantity;
string location;
uint seq_no;
uint phone;
uint price;
uint payment;
Shipment shipment;
bool init;
}
// structure of the invoice
struct Invoice
{
uint order_no;
uint phone;
bool init;
}
// store orders mapping
mapping (uint => Order) orders;
// store invoices mapping
mapping (uint => Invoice) invoices;
// Events that depicts the flow in a smart contract
uint order_seq;
uint invoice_seq;
event OrderSent (address buyer, string product, uint quantity, string location, uint order_no);
event PriceSent (address buyer, uint order_no, uint product_price, uint delivery_charge, uint delivery_date);
event Payment (address buyer, uint order_no, uint amount, uint phone, uint time_stamp);
event InvoiceSent (address buyer, uint invoice_no, uint order_no, uint delivery_date, address courier);
event OrderDelivered (address buyer, uint invoice_no, uint order_no, uint date, address courier);
// Buyer request order
function sendOrder(string product, uint quantity, string location) public {
require(msg.sender == buyer_address);
order_seq++;
orders[order_seq] = Order(product, quantity, location, order_seq, 0, 0, 0, Shipment(0, 0, 0, 0, 0, 0, false), true);
emit OrderSent(msg.sender, product, quantity, location, order_seq);
}
// line up orders
function query(uint seq_no) constant public returns (address, string, uint, string, uint, uint, uint)
{
require(orders[seq_no].init);
Order memory orderStruct;
orderStruct = orders[seq_no];
return (buyer_address, orderStruct.product, orderStruct.quantity, orderStruct.location, orderStruct.price, orderStruct.shipment.price, orderStruct.payment);
}
// seller sends the price and delivery_charge for the product
function sendPrice(uint order_no, uint price, uint delivery_charge, uint delivery_date) public
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment