Skip to content

Commit

Permalink
Issuance: remove multiplication of amount/token with precision (#176)
Browse files Browse the repository at this point in the history
* added factory method FromPublicKeys for creating multiscript payment

* remove multiplication of issuance amount/token with precision
  • Loading branch information
sekulicd authored Sep 29, 2021
1 parent 98e1164 commit 71dd075
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions transaction/data/issuance.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"index": 68,
"tokenFlag": 0,
"precision": 4,
"expectedAssetAmount": 10000000,
"expectedTokenAmount": 10000,
"expectedAssetAmount": 1000,
"expectedTokenAmount": 1,
"expectedEntropy": "3db9d8b4a9da087b42f29f34431412aaa24d63750bb31b9a2e263797248135e0",
"expectedAsset": "dedf795f74e8b52c6ff8a9ad390850a87b18aeb2be9d1967038308290093a893",
"expectedToken": "fa1074db60b598cf1d6d0318655125c26a2afc9fe57fb2bdff8d8f7408f8814d"
Expand Down
13 changes: 4 additions & 9 deletions transaction/issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"errors"
"math"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/vulpemventures/fastsha256"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 71dd075

Please sign in to comment.