Skip to content

Commit

Permalink
Pubkey issuance contract (#183)
Browse files Browse the repository at this point in the history
* added factory method FromPublicKeys for creating multiscript payment

* issuer_pubkey added

* contract hash update

* contract hash update

* refactor
  • Loading branch information
sekulicd authored Nov 23, 2021
1 parent 96f39d0 commit 2d0a253
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pset/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func TestUpdaterAddIssuance(t *testing.T) {
TokenAddress: "el1qqw3e3mk4ng3ks43mh54udznuekaadh9lgwef3mwgzrfzakmdwcvqpe4ppdaa3t44v3zv2u6w56pv6tc666fvgzaclqjnkz0sd",
},
expectedNumOuts: 2,
expectedAsset: "707953a405b1a79180ec7830e51d53997b3d1ff9aa614513266059dbfbbdbeb7",
expectedToken: "c99343e56d9783a816b866c48d182a9537d4979f1ed66d90ac6a49ec773daee9",
expectedAsset: "a5795a31c20057a117af937c9b28c119ada3c402c7c326a1c5e4fd1e95e1c588",
expectedToken: "2b06c9d643481c54b1440b615928b3811cf4f499787360c42a368ecc7fd92b2e",
},
{
args: AddIssuanceArgs{
Expand Down
9 changes: 5 additions & 4 deletions transaction/data/issuance.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"ticker": "TST",
"version": 0,
"precision": 0,
"entity": { "domain": "test.io" }
"entity": { "domain": "test.io" },
"issuer_pubkey": "02a9a7399de89ec2e7de876bbe0b512f78f13d5d0a3315047e5b14109c8bac38f2"
},
"expectedAssetAmount": 1000,
"expectedTokenAmount": 1,
"expectedEntropy": "2b73af1c9ae64a6903b3055361dd7b75082003a85374049982fc1e8f31b9a8cf",
"expectedAsset": "7af6e284f3729228895eddd45b39f72be65f8866d404e5c4374b2b97e7f178e7",
"expectedToken": "5b706edc0f72ea114e7a1f867c8b63a698944435e62699b9821deecc6d81bcef"
"expectedEntropy": "e405b6a4f891b7226cc3d9075c1a9c64ab73bb5f68e458dbe95340518c455bf7",
"expectedAsset": "210521aacc918a1c78106e720a667606f53eb72be593bc450329843bc3b959f5",
"expectedToken": "a0d7995a1d61446957834aaebd053a2c494dd9d14abc83486e4de2c4edd15943"
}
]
}
20 changes: 19 additions & 1 deletion transaction/issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type IssuanceContract struct {
Ticker string `json:"ticker"`
Version uint `json:"version"`
Precision uint `json:"precision"`
PubKey string `json:"issuer_pubkey"`
Entity IssuanceEntity `json:"entity"`
}

Expand Down Expand Up @@ -110,8 +111,12 @@ func NewTxIssuance(
return nil, err
}

contractHash = chainhash.HashB(serializedContract)
tmp, err := orderJsonKeysLexographically(serializedContract)
if err != nil {
return nil, err
}

contractHash = chainhash.HashB(tmp)
}

confAssetAmount, err := toConfidentialAssetAmount(
Expand Down Expand Up @@ -218,3 +223,16 @@ func toConfidentialTokenAmount(tokenAmount uint64) ([]byte, error) {
}
return confAmount[:], nil
}

func orderJsonKeysLexographically(bytes []byte) ([]byte, error) {
var ifce interface{}
err := json.Unmarshal(bytes, &ifce)
if err != nil {
return []byte{}, err
}
output, err := json.Marshal(ifce)
if err != nil {
return []byte{}, err
}
return output, nil
}
29 changes: 29 additions & 0 deletions transaction/issuance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,32 @@ func TestIssuanceGeneration(t *testing.T) {
)
}
}

func TestIsContractHashValid(t *testing.T) {
contract := IssuanceContract{
Name: "Tiero Token",
Ticker: "TIERO",
Version: 0,
Precision: 8,
PubKey: "02a9a7399de89ec2e7de876bbe0b512f78f13d5d0a3315047e5b14109c8bac38f2",
Entity: IssuanceEntity{
Domain: "tiero.github.io",
},
}

issuance, err := NewTxIssuance(10, 2, 8, &contract)
if err != nil {
t.Fatal(err)
}

assert.Equal(
t,
"d5c4363ee9cf2a4319c2f0ccc04cdb83d6213e4d26d94d70003c58eaf2473866",
hex.EncodeToString(elementsutil.ReverseBytes(issuance.ContractHash)), //validate online with reverse contract hash
)
assert.Equal(
t,
"663847f2ea583c00704dd9264d3e21d683db4cc0ccf0c219432acfe93e36c4d5",
hex.EncodeToString(issuance.ContractHash),
)
}

0 comments on commit 2d0a253

Please sign in to comment.