#57 - Sapling address in Human Readable format #57
2 changed files with 15 additions and 8 deletions
|
@ -157,17 +157,17 @@ decryptOrchardAction key encAction =
|
||||||
chrToByteString :: [Char] -> C.ByteString
|
chrToByteString :: [Char] -> C.ByteString
|
||||||
chrToByteString = C.pack
|
chrToByteString = C.pack
|
||||||
|
|
||||||
getSaplingFromUA :: BS.ByteString -> T.Text
|
getSaplingFromUA :: BS.ByteString -> Maybe T.Text
|
||||||
getSaplingFromUA uadd = do
|
getSaplingFromUA uadd = do
|
||||||
let a = isValidUnifiedAddress uadd
|
let a = isValidUnifiedAddress uadd
|
||||||
case a of
|
case a of
|
||||||
Nothing -> "xxx"
|
Nothing -> Nothing
|
||||||
Just a -> do
|
Just a -> do
|
||||||
let sraw = s_rec a
|
let sraw = s_rec a
|
||||||
case sraw of
|
case sraw of
|
||||||
Nothing -> "xxx"
|
Nothing -> Nothing
|
||||||
Just sraw -> do
|
Just sraw -> do
|
||||||
let net = ua_net a
|
let net = ua_net a
|
||||||
case net of
|
case net of
|
||||||
MainNet -> encodeBech32 (chrToByteString sapPaymentAddressHrp) ( getBytes sraw )
|
MainNet -> Just $ encodeBech32 (chrToByteString sapPaymentAddressHrp) ( getBytes sraw )
|
||||||
TestNet -> encodeBech32 (chrToByteString sapTestPaymentAddressHrp) ( getBytes sraw )
|
TestNet -> Just $ encodeBech32 (chrToByteString sapTestPaymentAddressHrp) ( getBytes sraw )
|
13
test/Spec.hs
13
test/Spec.hs
|
@ -844,11 +844,18 @@ main = do
|
||||||
let tb = zt_tBundle t'
|
let tb = zt_tBundle t'
|
||||||
print tb
|
print tb
|
||||||
show tb `shouldNotBe` ""
|
show tb `shouldNotBe` ""
|
||||||
describe "Extract Sapling Address" $ do
|
describe "Extract Sapling Address - UA Valid" $ do
|
||||||
let sr = getSaplingFromUA "u14a5c4ufn9feqvxssnvscep29j5cse4gjpg0w3w5vjhafn74hg9k73xgnxqv6m255n23weggr6j97c8kdwvn4pkz7rz6my52z8248gjmr7knlw536tcurs5km7knqnzez4cywudt3q6shr553hurduvljfeqvfzgegenfjashslkz3y4ykhxel6mrjp9gsm9xk7k6kdxn9y84kccmv8l"
|
let sr = getSaplingFromUA "u14a5c4ufn9feqvxssnvscep29j5cse4gjpg0w3w5vjhafn74hg9k73xgnxqv6m255n23weggr6j97c8kdwvn4pkz7rz6my52z8248gjmr7knlw536tcurs5km7knqnzez4cywudt3q6shr553hurduvljfeqvfzgegenfjashslkz3y4ykhxel6mrjp9gsm9xk7k6kdxn9y84kccmv8l"
|
||||||
it "Extract sapling address" $ do
|
it "Extract sapling address" $ do
|
||||||
print sr
|
case sr of
|
||||||
sr `shouldBe` "zs1waxrpde36rlrjdwfhnvw030sn29lzwmvmeupd8x2uuqgypaafx7mqcy0ep8yf2xtg30n5424t60"
|
Nothing -> assertFailure "UA invalid or does not contain a Sapling receiver"
|
||||||
|
Just t -> do
|
||||||
|
print t
|
||||||
|
t `shouldBe` "zs1waxrpde36rlrjdwfhnvw030sn29lzwmvmeupd8x2uuqgypaafx7mqcy0ep8yf2xtg30n5424t60"
|
||||||
|
describe "Extract Sapling Address - UA Invalid" $ do
|
||||||
|
let sr = getSaplingFromUA "u14a5c4ufn9qfevxssnvscep29j5cse4gjpg0w3w5vjhafn74hg9k73xgnxqv6m255n23weggr6j97c8kdwvn4pkz7rz6my52z8248gjmr7knlw536tcurs5km7knqnzez4cywudt3q6shr553hurduvljfeqvfzgegenfjashslkz3y4ykhxel6mrjp9gsm9xk7k6kdxn9y84kccmv8l"
|
||||||
|
it "Try to extract sapling address from invalid UA" $ do
|
||||||
|
sr `shouldBe` Nothing
|
||||||
|
|
||||||
|
|
||||||
-- | Properties
|
-- | Properties
|
||||||
|
|
Loading…
Reference in a new issue