Skip to content

Commit

Permalink
update buy artworks function
Browse files Browse the repository at this point in the history
  • Loading branch information
hvthhien committed Jun 7, 2024
1 parent 6134032 commit d3edc08
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 50 deletions.
163 changes: 116 additions & 47 deletions contracts/feralfile-exhibition-v4_2/feralfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ func (c *FeralfileExhibitionV4_2Contract) Deploy(
wallet *ethereum.Wallet,
arguments json.RawMessage) (string, string, error) {
var params struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Signer common.Address `json:"signer"`
Vault common.Address `json:"vault"`
CostReceiver common.Address `json:"cost_receiver"`
ContractURI string `json:"contract_uri"`
IsBurnable bool `json:"is_burnable"`
IsBridgeable bool `json:"is_bridgeable"`
SeriesIDs []*big.Int `json:"series_ids"`
SeriesMaxSupplies []*big.Int `json:"series_max_supplies"`
ERC20Contract common.Address `json:"erc20_contract"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Signer common.Address `json:"signer"`
Vault common.Address `json:"vault"`
CostReceiver common.Address `json:"cost_receiver"`
ContractURI string `json:"contract_uri"`
IsBurnable bool `json:"is_burnable"`
IsBridgeable bool `json:"is_bridgeable"`
SeriesIDs []*big.Int `json:"series_ids"`
SeriesMaxSupplies []*big.Int `json:"series_max_supplies"`
SeriesNextTokenIds []*big.Int `json:"series_next_token_ids"`
}

if err := json.Unmarshal(arguments, &params); err != nil {
Expand All @@ -67,7 +67,7 @@ func (c *FeralfileExhibitionV4_2Contract) Deploy(
params.ContractURI,
params.SeriesIDs,
params.SeriesMaxSupplies,
params.ERC20Contract,
params.SeriesNextTokenIds,
)
if err != nil {
return "", "", err
Expand Down Expand Up @@ -128,12 +128,12 @@ func (c *FeralfileExhibitionV4_2Contract) Call(
return nil, errors.New("Invalid parameters")
}

mintData, ok := params[0].([]feralfilev4.FeralfileExhibitionV42MintDataWithIndex)
mintData, ok := params[0].([]feralfilev4.FeralfileExhibitionV4MintData)
if !ok {
return nil, errors.New("Invalid token mint parameters")
}

return contract.MintArtworksWithIndex(t, mintData)
return contract.MintArtworks(t, mintData)
case "setTokenBaseURI":
if len(params) != 1 {
return nil, errors.New("Invalid parameters")
Expand Down Expand Up @@ -184,6 +184,32 @@ func (c *FeralfileExhibitionV4_2Contract) Call(
}

return contract.BuyArtworks(t, r, s, v, saleData)
case "buyBulkArtworks":
if len(params) != 4 {
return nil, errors.New("Invalid parameters")
}

r, ok := params[0].([32]byte)
if !ok {
return nil, fmt.Errorf("invalid r")
}

s, ok := params[1].([32]byte)
if !ok {
return nil, fmt.Errorf("invalid s")
}

v, ok := params[2].(uint8)
if !ok {
return nil, fmt.Errorf("invalid v")
}

saleData, ok := params[3].(feralfilev4.IFeralfileSaleDataV2SaleDataV2)
if !ok {
return nil, fmt.Errorf("invalid sale data")
}

return contract.BuyBulkArtworks(t, r, s, v, saleData)
case "setApprovalForAll":
if len(params) != 2 {
return nil, errors.New("Invalid parameters")
Expand All @@ -208,12 +234,6 @@ func (c *FeralfileExhibitionV4_2Contract) Call(
}

return contract.SetAdvanceSetting(t, params[0].([]common.Address), params[1].([]*big.Int))
case "updateTokenInformation":
if len(params) != 4 {
return nil, errors.New("Invalid parameters")
}

return contract.UpdateTokenInformation(t, params[0].(*big.Int), params[1].(string), params[2].([]byte), params[3].(*big.Int))
default:
return nil, fmt.Errorf("unsupported method")
}
Expand All @@ -232,11 +252,7 @@ func (c *FeralfileExhibitionV4_2Contract) Pack(
return nil, err
}

mappedMethod := method
if method == "mintArtworks" {
mappedMethod = "mintArtworksWithIndex"
}
return abi.Pack(mappedMethod, parsedArgs...)
return abi.Pack(method, parsedArgs...)
}

func (c *FeralfileExhibitionV4_2Contract) Parse(
Expand All @@ -263,10 +279,9 @@ func (c *FeralfileExhibitionV4_2Contract) Parse(
return []interface{}{tokenIDs}, nil
case "mintArtworks":
var params []struct {
SeriesID ethereum.BigInt `json:"series_id"`
TokenID ethereum.BigInt `json:"token_id"`
Owner common.Address `json:"owner"`
TokenIndex ethereum.BigInt `json:"token_index"`
SeriesID ethereum.BigInt `json:"series_id"`
TokenID ethereum.BigInt `json:"token_id"`
Owner common.Address `json:"owner"`
}
if err := json.Unmarshal(arguments, &params); err != nil {
return nil, err
Expand All @@ -275,13 +290,12 @@ func (c *FeralfileExhibitionV4_2Contract) Parse(
return nil, errors.New("Invalid token mint parameters")
}

mintData := make([]feralfilev4.FeralfileExhibitionV42MintDataWithIndex, len(params))
mintData := make([]feralfilev4.FeralfileExhibitionV4MintData, len(params))
for i := 0; i < len(params); i++ {
mintData[i] = feralfilev4.FeralfileExhibitionV42MintDataWithIndex{
SeriesId: &params[i].SeriesID.Int,
TokenId: &params[i].TokenID.Int,
Owner: params[i].Owner,
TokenIndex: &params[i].TokenIndex.Int,
mintData[i] = feralfilev4.FeralfileExhibitionV4MintData{
SeriesId: &params[i].SeriesID.Int,
TokenId: &params[i].TokenID.Int,
Owner: params[i].Owner,
}
}

Expand Down Expand Up @@ -380,6 +394,73 @@ func (c *FeralfileExhibitionV4_2Contract) Parse(
PayByVaultContract: params.SaleData.PayByVaultContract,
}

return []interface{}{r32Val, s32Val, uint8(vVal), saleData}, nil
case "buyBulkArtworks":
var params struct {
SaleData struct {
Price ethereum.BigInt `json:"price"`
Cost ethereum.BigInt `json:"cost"`
ExpiryTime ethereum.BigInt `json:"expiryTime"`
Destination common.Address `json:"destination"`
Nonce ethereum.BigInt `json:"nonce"`
SeriesID ethereum.BigInt `json:"seriesId"`
Quantity uint16 `json:"quantity"`
RevenueShares []struct {
Recipient common.Address `json:"recipient"`
Bps ethereum.BigInt `json:"bps"`
} `json:"revenueShares"`
PayByVaultContract bool `json:"payByVaultContract"`
} `json:"saleData"`
R string `json:"r"`
S string `json:"s"`
V string `json:"v"`
}

if err := json.Unmarshal(arguments, &params); err != nil {
return nil, err
}

rVal, err := hex.DecodeString(strings.Replace(params.R, "0x", "", -1))
if err != nil {
return nil, err
}
sVal, err := hex.DecodeString(strings.Replace(params.S, "0x", "", -1))
if err != nil {
return nil, err
}
vVal, err := strconv.ParseUint(strings.Replace(params.V, "0x", "", -1), 16, 64)
if err != nil {
return nil, err
}
if len(rVal) != 32 || len(sVal) != 32 {
return nil, errors.New("required signature length is 32")
}
var r32Val [32]byte
var s32Val [32]byte
copy(r32Val[:], rVal)
copy(s32Val[:], sVal)

revenueShares := make([]feralfilev4.IFeralfileSaleDataRevenueShare, 0)
for _, v := range params.SaleData.RevenueShares {
bps := v.Bps.Int
revenueShares = append(revenueShares, feralfilev4.IFeralfileSaleDataRevenueShare{
Recipient: v.Recipient,
Bps: &bps,
})
}

saleData := feralfilev4.IFeralfileSaleDataV2SaleDataV2{
Price: &params.SaleData.Price.Int,
Cost: &params.SaleData.Cost.Int,
ExpiryTime: &params.SaleData.ExpiryTime.Int,
Destination: params.SaleData.Destination,
Nonce: &params.SaleData.Nonce.Int,
SeriesID: &params.SaleData.SeriesID.Int,
Quantity: params.SaleData.Quantity,
RevenueShares: revenueShares,
PayByVaultContract: params.SaleData.PayByVaultContract,
}

return []interface{}{r32Val, s32Val, uint8(vVal), saleData}, nil
case "setAdvanceSetting":
var params struct {
Expand All @@ -397,18 +478,6 @@ func (c *FeralfileExhibitionV4_2Contract) Parse(
}

return []interface{}{params.AdvanceAddresses, advanceAmounts}, nil
case "updateTokenInformation":
var params struct {
TokenID ethereum.BigInt `json:"token_id"`
ImageURI string `json:"image_uri"`
Paramters []byte `json:"parameters"`
CoinAmount ethereum.BigInt `json:"coin_amount"`
}
if err := json.Unmarshal(arguments, &params); err != nil {
return nil, err
}

return []interface{}{&params.TokenID.Int, params.ImageURI, params.Paramters, &params.CoinAmount.Int}, nil
default:
return nil, fmt.Errorf("unsupported method")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bitmark-inc/account-vault-ethereum
go 1.20

require (
github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b
github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21
github.com/ethereum/go-ethereum v1.13.10
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b h1:+8cGdcQknU4nX430a9qgBvgBH1oeUMsnD46ubszByx4=
github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240529042939-0b6972bb280b/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY=
github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21 h1:XzdTNI5E5PUcMpSzZM72vbTSqHizH/TldfNiu76frII=
github.com/bitmark-inc/feralfile-exhibition-smart-contract/go-binding v0.0.0-20240607014320-77c7b7083b21/go.mod h1:shvtsuJyQJnByXKqf9n/jpjL4++FSJCFjXR/08iBnFY=
github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88=
github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
Expand Down

0 comments on commit d3edc08

Please sign in to comment.