From 71dd075222b5880722fcdb922fee3150cd5f383e Mon Sep 17 00:00:00 2001 From: Dusan Sekulic Date: Wed, 29 Sep 2021 18:32:04 +0200 Subject: [PATCH] Issuance: remove multiplication of amount/token with precision (#176) * added factory method FromPublicKeys for creating multiscript payment * remove multiplication of issuance amount/token with precision --- transaction/data/issuance.json | 4 ++-- transaction/issuance.go | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/transaction/data/issuance.json b/transaction/data/issuance.json index ff39f4b..4ec4d8c 100644 --- a/transaction/data/issuance.json +++ b/transaction/data/issuance.json @@ -7,8 +7,8 @@ "index": 68, "tokenFlag": 0, "precision": 4, - "expectedAssetAmount": 10000000, - "expectedTokenAmount": 10000, + "expectedAssetAmount": 1000, + "expectedTokenAmount": 1, "expectedEntropy": "3db9d8b4a9da087b42f29f34431412aaa24d63750bb31b9a2e263797248135e0", "expectedAsset": "dedf795f74e8b52c6ff8a9ad390850a87b18aeb2be9d1967038308290093a893", "expectedToken": "fa1074db60b598cf1d6d0318655125c26a2afc9fe57fb2bdff8d8f7408f8814d" diff --git a/transaction/issuance.go b/transaction/issuance.go index c97470e..b35a723 100644 --- a/transaction/issuance.go +++ b/transaction/issuance.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "errors" - "math" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/vulpemventures/fastsha256" @@ -117,14 +116,12 @@ func NewTxIssuance( confAssetAmount, err := toConfidentialAssetAmount( assetAmount, - precision, ) if err != nil { return nil, err } confTokenAmount, err := toConfidentialTokenAmount( tokenAmount, - precision, ) if err != nil { return nil, err @@ -202,22 +199,20 @@ func (issuance *TxIssuanceExtended) GenerateReissuanceToken(flag uint) ([]byte, return token[:], nil } -func toConfidentialAssetAmount(assetAmount uint64, precision uint) ([]byte, error) { - amount := assetAmount * uint64(math.Pow10(int(precision))) - confAmount, err := elementsutil.SatoshiToElementsValue(amount) +func toConfidentialAssetAmount(assetAmount uint64) ([]byte, error) { + confAmount, err := elementsutil.SatoshiToElementsValue(assetAmount) if err != nil { return nil, err } return confAmount[:], nil } -func toConfidentialTokenAmount(tokenAmount uint64, precision uint) ([]byte, error) { +func toConfidentialTokenAmount(tokenAmount uint64) ([]byte, error) { if tokenAmount == 0 { return []byte{0x00}, nil } - amount := tokenAmount * uint64(math.Pow10(int(precision))) - confAmount, err := elementsutil.SatoshiToElementsValue(amount) + confAmount, err := elementsutil.SatoshiToElementsValue(tokenAmount) if err != nil { return nil, err }