// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

import "./PriceAggregator.sol";

contract PriceNode {
    address public owner;
    PriceAggregator[] public aggregators;

    constructor() public {
        owner = msg.sender;
    }

    function register(
        uint8 decimals,
        string memory description,
        int256 initialAnswer
    ) external {
        require(msg.sender == owner);
        PriceAggregator aggregator = new PriceAggregator(
            decimals,
            description,
            initialAnswer
        );
        aggregators.push(aggregator);
    }

    function setAnswers(
        uint256[] calldata indexes,
        int256[] calldata newAnswers
    ) external {
        require(msg.sender == owner);
        for (uint256 i = 0; i < indexes.length; i++) {
            PriceAggregator aggregator = aggregators[i];
            aggregator.setLatestAnswer(newAnswers[i]);
        }
    }

    function setOwner(address newOwner) external {
        require(msg.sender == owner);
        owner = newOwner;
    }
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"aggregators","outputs":[{"internalType":"contract PriceAggregator","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"decimals","type":"uint8"},{"internalType":"string","name":"description","type":"string"},{"internalType":"int256","name":"initialAnswer","type":"int256"}],"name":"register","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"indexes","type":"uint256[]"},{"internalType":"int256[]","name":"newAnswers","type":"int256[]"}],"name":"setAnswers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"}]