Skip to content

Commit

Permalink
Fix PubKey.GetScriptAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Sep 28, 2014
1 parent 6b2e88c commit 640e176
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions NBitcoin.Tests/ColoredCoinsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ public class ColoredCoinsTests
[Fact]
public void CanCreateAssetAddress()
{
//The issuer first generates a private key: 18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725.
var key = new Key(TestUtils.ParseHex("18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725"));
//He calculates the corresponding address: 16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM.
var address = key.PubKey.Decompress().GetAddress(Network.Main);
Assert.Equal("16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM", address.ToString());

//Next, he builds the Pay-to-PubKey-Hash script associated to that address: OP_DUP OP_HASH160 010966776006953D5567439E5E39F86A0D273BEE OP_EQUALVERIFY OP_CHECKSIG
Script script = Script.CreateFromDestinationAddress(address);
Assert.Equal("OP_DUP OP_HASH160 010966776006953D5567439E5E39F86A0D273BEE OP_EQUALVERIFY OP_CHECKSIG", script.ToString().ToUpper());

//36hBrMeUfevFPZdY2iYSHVaP9jdLd9Np4R.
var scriptAddress = script.GetScriptAddress(Network.Main);
Assert.Equal("36hBrMeUfevFPZdY2iYSHVaP9jdLd9Np4R", scriptAddress.ToString());


Assert.Equal("36hBrMeUfevFPZdY2iYSHVaP9jdLd9Np4R",key.PubKey.Decompress().GetScriptAddress(Network.Main).ToString());
}

}
Expand Down
4 changes: 3 additions & 1 deletion NBitcoin/NBitcoin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@
<Name>Mono.Nat</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="ColoredCoin\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion NBitcoin/PubKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public BitcoinAddress GetAddress(Network network)
}
public BitcoinScriptAddress GetScriptAddress(Network network)
{
var redeem = new PayToScriptHashTemplate().GenerateScriptPubKey(new PayToPubkeyTemplate().GenerateScriptPubKey(this));
var redeem = new PayToPubkeyHashTemplate().GenerateScriptPubKey(this);
return new BitcoinScriptAddress(redeem.ID, network);
}

Expand Down

0 comments on commit 640e176

Please sign in to comment.