|
| 1 | +/* |
| 2 | + * Copyright 2022 The OpenWallet Authors |
| 3 | + * This file is part of the OpenWallet library. |
| 4 | + * |
| 5 | + * The OpenWallet library is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * The OpenWallet library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + */ |
| 15 | + |
| 16 | +package openwallet |
| 17 | + |
| 18 | +type NFT struct { |
| 19 | + Symbol string `json:"symbol"` //@required 主币的symbol |
| 20 | + Address string `json:"address"` |
| 21 | + Token string `json:"token"` //@required NFT的symbol |
| 22 | + Protocol string `json:"protocol"` |
| 23 | + Name string `json:"name"` |
| 24 | + TokenID string `json:"tokenID"` //@required |
| 25 | +} |
| 26 | + |
| 27 | +type NFTBalance struct { |
| 28 | + Contract *NFT |
| 29 | + Balance *string |
| 30 | +} |
| 31 | + |
| 32 | +// NFTEventType |
| 33 | +const ( |
| 34 | + NFTEventTypeTransferred = 0 //转账 |
| 35 | + NFTEventTypeMinted = 1 //铸造 |
| 36 | + NFTEventTypeBurned = 2 //销毁 |
| 37 | +) |
| 38 | + |
| 39 | +type NFTTransfer struct { |
| 40 | + Tokens []NFT `json:"tokens"` //@required nft |
| 41 | + Operator string `json:"operator"` //required 被授权转账的操作者 |
| 42 | + From string `json:"from"` //@required 发送者 |
| 43 | + To string `json:"to"` //@required 接受者 |
| 44 | + Amounts []string `json:"amounts"` //@required erc1155 token有数量 |
| 45 | + EventType uint64 `json:"eventType"` //@required |
| 46 | +} |
| 47 | + |
| 48 | +type NFTApproval struct { |
| 49 | + Token *NFT `json:"token"` //@required nft |
| 50 | + Owner string `json:"owner"` //@required nft拥有者 |
| 51 | + Operator string `json:"operator"` //required 被授权的操作者 |
| 52 | + IsAll bool `json:"isAll"` //@required 是否全部NFT,true:token = null,false,token = *NFT |
| 53 | +} |
| 54 | + |
| 55 | +//NFTContractDecoder NFT智能合约解析器 |
| 56 | +type NFTContractDecoder interface { |
| 57 | + //GetNFTBalanceByAddress 查询地址NFT余额列表 |
| 58 | + GetNFTBalanceByAddress(contract []*NFT, owner []string) ([]*NFTBalance, *Error) |
| 59 | + //GetNFTOwnerByTokenID 查询地址token的拥有者 |
| 60 | + GetNFTOwnerByTokenID(contract *NFT) (string, *Error) |
| 61 | + //GetMetaDataOfNFT 查询NFT的MetaData |
| 62 | + GetMetaDataOfNFT(contract *NFT) (string, *Error) |
| 63 | + //GetNFTTransfer 从event解析NFT转账信息 |
| 64 | + GetNFTTransfer(event *SmartContractEvent) (*NFTTransfer, *Error) |
| 65 | +} |
| 66 | + |
| 67 | +type NFTContractDecoderBase struct { |
| 68 | +} |
| 69 | + |
| 70 | +//GetNFTBalanceByAddress 查询地址NFT余额列表 |
| 71 | +func (decoder *NFTContractDecoderBase) GetNFTBalanceByAddress(contract []*NFT, owner []string) ([]*NFTBalance, *Error) { |
| 72 | + return nil, Errorf(ErrSystemException, "GetNFTBalanceByAddress not implement") |
| 73 | +} |
| 74 | + |
| 75 | +//GetNFTOwnerByTokenID 查询地址token的拥有者 |
| 76 | +func (decoder *NFTContractDecoderBase) GetNFTOwnerByTokenID(contract *NFT) (string, *Error) { |
| 77 | + return "", Errorf(ErrSystemException, "GetNFTBalanceByAddress not implement") |
| 78 | +} |
| 79 | + |
| 80 | +//GetMetaDataOfNFT 查询NFT的MetaData |
| 81 | +func (decoder *NFTContractDecoderBase) GetMetaDataOfNFT(contract *NFT) (string, *Error) { |
| 82 | + return "", Errorf(ErrSystemException, "GetNFTBalanceByAddress not implement") |
| 83 | +} |
| 84 | + |
| 85 | +//GetNFTTransfer 从event解析NFT转账信息 |
| 86 | +func (decoder *NFTContractDecoderBase) GetNFTTransfer(event *SmartContractEvent) (*NFTTransfer, *Error) { |
| 87 | + return nil, Errorf(ErrSystemException, "GetNFTBalanceByAddress not implement") |
| 88 | +} |
0 commit comments