package org.ethereum.config.blockchain;

import org.apache.commons.lang3.tuple.Pair;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.core.BlockHeader;
import org.ethereum.validator.BlockHeaderRule;
import org.ethereum.validator.BlockHeaderValidator;
import org.ethereum.validator.ExtraDataPresenceRule;
import org.spongycastle.util.encoders.Hex;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Stan Reshetnyk on 26.12.16.
 */
public abstract class AbstractDaoConfig extends FrontierConfig {

    /**
     * Hardcoded values from live network
     */
    public static final long ETH_FORK_BLOCK_NUMBER = 1_920_000;

    public static final byte[] DAO_EXTRA_DATA = Hex.decode("64616f2d686172642d666f726b");

    // TODO find a way to remove block number value from blockchain config
    protected long forkBlockNumber;

    // set in child classes
    protected boolean supportFork;

    private List<Pair<Long, BlockHeaderValidator>> validator;

    private BlockchainConfig parent;

    protected void initDaoConfig(BlockchainConfig parent, long forkBlockNumber) {
        this.parent = parent;
        this.forkBlockNumber = forkBlockNumber;
        BlockHeaderRule rule = new ExtraDataPresenceRule(DAO_EXTRA_DATA, supportFork);
        validator = Arrays.asList(Pair.of(forkBlockNumber, new BlockHeaderValidator(Arrays.asList(rule))));
    }

    @Override
    public List<Pair<Long, BlockHeaderValidator>> headerValidators() {
        return validator;
    }

    @Override
    public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) {
        return this.parent.calcDifficulty(curBlock, parent);
    }
}

@@ -34,16 +34,60 @@
 chain;%0A%0A
+import org.apache.commons.lang3.ArrayUtils;%0A
 import o
@@ -201,24 +201,62 @@
 lockHeader;%0A
+import org.ethereum.core.Transaction;%0A
 import org.e
@@ -1236,16 +1236,64 @@
 parent;%0A
+        this.constants = parent.getConstants();%0A
         
@@ -1813,11 +1813,270 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public long getTransactionCost(Transaction tx) %7B%0A        return parent.getTransactionCost(tx);%0A    %7D%0A%0A    @Override%0A    public boolean acceptTransactionSignature(Transaction tx) %7B%0A        return parent.acceptTransactionSignature(tx);%0A    %7D
 %0A%7D%0A

Allow configure DAO config without without Homestead config