-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbcp_nft_v1.go
55 lines (47 loc) · 1.82 KB
/
bcp_nft_v1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package script
import (
"encoding/binary"
)
func decodeNFTIssue(scriptLen int, pkScript []byte, txo *TxoData) bool {
// nft issue
txo.CodeType = CodeType_NFT
genesisIdLen := 40
genesisOffset := scriptLen - 37 - 1 - genesisIdLen
tokenSupplyOffset := scriptLen - 1 - 8
tokenIndexOffset := tokenSupplyOffset - 8
addressOffset := tokenIndexOffset - 20
dataLen := 1 + 1 + genesisIdLen + 1 + 37 // opreturn + pushdata + pushdata + data
nft := &NFTData{
TokenSupply: binary.LittleEndian.Uint64(pkScript[tokenSupplyOffset : tokenSupplyOffset+8]),
TokenIndex: binary.LittleEndian.Uint64(pkScript[tokenIndexOffset : tokenIndexOffset+8]),
}
nft.TokenIndex = nft.TokenSupply
txo.NFT = nft
txo.GenesisIdLen = uint8(genesisIdLen)
copy(txo.CodeHash[:], GetHash160(pkScript[:scriptLen-dataLen]))
copy(txo.GenesisId[:], pkScript[genesisOffset:genesisOffset+genesisIdLen])
copy(txo.AddressPkh[:], pkScript[addressOffset:addressOffset+20])
txo.HasAddress = true
return true
}
func decodeNFTTransfer(scriptLen int, pkScript []byte, txo *TxoData) bool {
// nft transfer
txo.CodeType = CodeType_NFT
genesisIdLen := 40
genesisOffset := scriptLen - 61 - 1 - genesisIdLen
metaTxIdOffset := scriptLen - 1 - 32
tokenIndexOffset := metaTxIdOffset - 8
addressOffset := tokenIndexOffset - 20
dataLen := 1 + 1 + genesisIdLen + 1 + 61 // opreturn + pushdata + pushdata + data
nft := &NFTData{
TokenIndex: binary.LittleEndian.Uint64(pkScript[tokenIndexOffset : tokenIndexOffset+8]),
}
txo.NFT = nft
txo.GenesisIdLen = uint8(genesisIdLen)
copy(txo.CodeHash[:], GetHash160(pkScript[:scriptLen-dataLen]))
copy(txo.GenesisId[:], pkScript[genesisOffset:genesisOffset+genesisIdLen])
copy(nft.MetaTxId[:], pkScript[metaTxIdOffset:metaTxIdOffset+32])
copy(txo.AddressPkh[:], pkScript[addressOffset:addressOffset+20])
txo.HasAddress = true
return true
}