Skip to content

Instantly share code, notes, and snippets.

import { Injectable, Inject } from '@angular/core';
import { AttackChangeService } from './attack-change.services';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable, of, from } from 'rxjs';
import { tap, switchMap, exhaustMap, map, catchError } from 'rxjs/operators';
import * as fromAction from './attack-change.actions';
@Effect()
GetAttack$: Observable<Action> = this.actions$.pipe(
ofType(fromAction.ActionTypes.GET_ATTACK),
switchMap(() => this.ethSrv.getAttack().pipe(
map((name: string) => new fromAction.GetAttackSuccess(name)),
catchError(err => of(new fromAction.EthError(err)))
)),
);
public getAttack(): Observable<string> {
return from(this.smartContract.deployed()).pipe(
switchMap((instance: any) => from<string>(instance.currentAttack())
));
}
@Effect()
SetAttack$: Observable<Action> = this.actions$.pipe(
ofType(fromAction.ActionTypes.SET_ATTACK),
map((action: fromAction.SetAttack) => action.payload),
exhaustMap((name: string) => this.ethSrv.setAttack(name).pipe(
tap(result => console.log('result', result)),
// retrieve the log information that will contain the event data.
map(result => result.logs[0].args[0]),
map((newName: string) => new fromAction.SetAttackSuccess(newName)),
catchError(err => of(new fromAction.EthError(err)))
public setAttack(name: string): Observable<any> {
return from(this.smartContract.deployed()).pipe(
switchMap((instance: any) =>
from(instance.changeAttack(name, {from: this.web3.eth.defaultAccount}))
));
}
pragma solidity ^0.5.5;
// Importing OpenZeppelin's SafeMath Implementation
import 'openzeppelin-solidity/contracts/math/SafeMath.sol';
contract FleaMarket {
mapping(string => address) elements;
string[] keys;
address public lastContractAddress;
{
"name": "fleamarketdapp",
"version": "1.0.0",
"description": "",
"author": "Alex Yevseyevich",
"dependencies": {
"fs": "0.0.1-security",
"openzeppelin-solidity": "^2.2.0",
"truffle-hdwallet-provider": "^1.0.5"
}
module.exports = {
networks: {
ropsten: {
provider: () => {
try {
const fileContents = readFileSync(path.join(__dirname, 'secret.json'), 'utf8')
const data = JSON.parse(fileContents);
const privateKey = data.mnemonic;
@alexytiger
alexytiger / spinner.actions.ts
Last active December 24, 2019 05:51
e-book
import { createAction, union } from '@ngrx/store';
export const show = createAction('[Spinner] Show');
export const hide = createAction('[Spinner] Hide');
@alexytiger
alexytiger / error.actions.ts
Last active December 24, 2019 05:59
e-book
import { createAction, props } from '@ngrx/store';
export const errorMessage = createAction('[Error] Error Message', props<{ errorMsg: string }>());