Skip to content

Instantly share code, notes, and snippets.

import { Injectable } from '@angular/core';
import { P2pBazaarAnchorModule } from '../p2p-bazaar.anchor.module';
import { Provider } from '../../core/services/tokens';
import { Observable, from, of, zip } from 'rxjs';
import { map, tap, switchMap } from 'rxjs/operators';
import { ethers, Contract, utils } from 'ethers';
import { PurchaseContractModel, ContractState} from '../models';
@Injectable({ providedIn: P2pBazaarAnchorModule })
export class PurchaseContractService {
export enum ContractState{
'Created' = 0,
'Locked',
'Inactive'
};
export interface PurchaseContractModel {
productKey: string;
contractAddress: string;
sellerAddress: string;
import * as fromRoot from '../../../core/store/reducers';
import * as fromIpfsUpload from './ipfs-upload.reducer';
import * as fromProducts from './purchase-contract.reducer';
export interface PurchaseContractState {
ipfsUpload: fromIpfsUpload.State;
products: fromProducts.State
}
export interface AppState extends fromRoot.AppState {
createProduct$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.createPurchaseContract),
map(action => action.payload),
exhaustMap((payload) => {
return this.fleaSrv.createPurchaseContract(payload).pipe(
tap(address => console.log('Contract address: ', address)),
switchMap((address: string) => {
showSnackbarOnCreateContract$ = createEffect(() =>
this.actions$.pipe(
ofType(PurchaseContractActions.createPurchaseContractSuccess),
map((payload) => {
const msg: SnackBarInterface = {
message: `New smart product contract has been created successfully: Address: ${payload.product.contractAddress}`,
color: AppearanceColor.Success
};
addProduct$ = createEffect(() =>
this.actions$.pipe(
ofType(PurchaseContractActions.createPurchaseContractSuccess),
switchMap((payload) => {
return this.productSrv.loadPurchaseContract(payload.address).pipe(
tap(product => console.log('purchase contract:', product)),
map(product => PurchaseContractActions.addProduct({product})),
catchError((err: Error) =>
export interface PurchaseWidgetModel {
productKey: string;
contractAddress: string;
}
pragma solidity 0.5.11;
import "./HitchensUnorderedKeySet.sol";
contract FleaMarket {
using HitchensUnorderedKeySetLib for HitchensUnorderedKeySetLib.Set;
HitchensUnorderedKeySetLib.Set widgetSet;
struct WidgetStruct {
address contractAddress;
compilers: {
solc: {
version: "0.5.11",
// docker: true,
settings: {
optimizer: {
enabled: true,
runs: 200
},
}
const FleaMarket = artifacts.require("../contracts/FleaMarket");
const SafeRemotePurchase = artifacts.require("../build/contracts/SafeRemotePurchase");
var BN = web3.utils.BN;
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised).should();
contract("FleaMarket", accounts => {