after stating the facts, delivered the opinion of the court.
Much was said in argument at bar upon the question of when a contract is to be regarded as completed under the circumstances here presented, and the discussion concerning the authority of the Secretary of War to review the action of an officer of engineers in such a case, and to direct a new adjudication, has taken a wide range. We deem the consideration of both these points unnecessary in view of the relator’s
*308
bids under the second advertisement and specifications, and his contract to do the work at a less price and under new conditions. It is elementary law that mandamus will only lie to enforce a ministerial duty, as contra-distinguished from a duty which is merely discretionary. This doctrine was clearly and fully set forth by Chief Justice Marshall in
Marbury
v.
Madison,
The duty to be enforced by mandamus must not only be merely ministerial, but it must be a. duty which exists at the time when the application for the mandamus is made. Thus in the case of
Ex parte Rowland,
Moreover, the obligation must be both peremptory, and plainly defined. The law must not only authorize the act,
Commonwealth
v.
Boutwell,
But even if the writ of mandamus could be so perverted as to make it serve the purposes of an ordinary suit, the relator is in no position to avail himself of such relief. He entered of his own accord into the second contract and has acted under it and has taken advantages which resulted from his action under it, having received the compensation which was to be paid under its terms. Having done all this, he is estopped from denying the validity of the contract.
Oregonian Railway
v.
Oregon Railway,
10 Sawyer, 464. Nor does the fact that in making his second contract, the relator protested that he had rights under the first better his position. If he had any such rights and desired to maintain them, he should have
*310
abstained from putting himself in a position where he voluntarily took advantage of the second opportunity to secure the work. A party cannot avoid the legal consequences of his. acts by protesting at the time he does them that he does not intend to subject himself to such consequences. In the case of
The Bank of the United States
v.
The Bank of
Washington,
The whole case of this relator is covered by
Gilbert
v.
United States,
Judgment affirmed.
