1: <?php declare( strict_types = 1 );
2:
3: namespace Waves\Transactions;
4:
5: use Exception;
6: use Waves\Account\PrivateKey;
7: use Waves\Common\Base58String;
8: use Waves\Account\PublicKey;
9: use Waves\Common\ExceptionCode;
10: use Waves\Common\Json;
11: use Waves\Model\AssetId;
12: use Waves\Model\ChainId;
13:
14: use Waves\Transactions\UpdateAssetInfoTransaction as CurrentTransaction;
15:
16: class UpdateAssetInfoTransaction extends Transaction
17: {
18: const TYPE = 17;
19: const LATEST_VERSION = 1;
20: const MIN_FEE = 100_000;
21:
22: private AssetId $assetId;
23: private string $name;
24: private string $description;
25:
26: static function build( PublicKey $sender, AssetId $assetId, string $name, string $description ): CurrentTransaction
27: {
28: $tx = new CurrentTransaction;
29: $tx->setBase( $sender, CurrentTransaction::TYPE, CurrentTransaction::LATEST_VERSION, CurrentTransaction::MIN_FEE );
30:
31: // RENAME TRANSACTION
32: {
33: $tx->setAssetId( $assetId );
34: $tx->setName( $name );
35: $tx->setDescription( $description );
36: }
37:
38: return $tx;
39: }
40:
41: function getUnsigned(): CurrentTransaction
42: {
43: // VERSION
44: if( $this->version() !== CurrentTransaction::LATEST_VERSION )
45: throw new Exception( __FUNCTION__ . ' unexpected version = ' . $this->version(), ExceptionCode::UNEXPECTED );
46:
47: // BASE
48: $pb_Transaction = $this->getProtobufTransactionBase();
49:
50: // RENAME TRANSACTION
51: {
52: $pb_TransactionData = new \Waves\Protobuf\UpdateAssetInfoTransactionData;
53: // ASSET
54: {
55: $pb_TransactionData->setAssetId( $this->assetId()->bytes() );
56: }
57: // NAME
58: {
59: $pb_TransactionData->setName( $this->name() );
60: }
61: // DESCRIPTION
62: {
63: $pb_TransactionData->setDescription( $this->description() );
64: }
65: }
66:
67: // RENAME TRANSACTION
68: $this->setBodyBytes( $pb_Transaction->setUpdateAssetInfo( $pb_TransactionData )->serializeToString() );
69: return $this;
70: }
71:
72: function assetId(): AssetId
73: {
74: if( !isset( $this->assetId ) )
75: $this->assetId = $this->json->get( 'assetId' )->asAssetId();
76: return $this->assetId;
77: }
78:
79: function setAssetId( AssetId $assetId ): CurrentTransaction
80: {
81: $this->assetId = $assetId;
82: $this->json->put( 'assetId', $assetId->toJsonValue() );
83: return $this;
84: }
85:
86: function name(): string
87: {
88: if( !isset( $this->name ) )
89: $this->name = $this->json->get( 'name' )->asString();
90: return $this->name;
91: }
92:
93: function setName( string $name ): CurrentTransaction
94: {
95: $this->name = $name;
96: $this->json->put( 'name', $name );
97: return $this;
98: }
99:
100: function description(): string
101: {
102: if( !isset( $this->description ) )
103: $this->description = $this->json->get( 'description' )->asString();
104: return $this->description;
105: }
106:
107: function setDescription( string $description ): CurrentTransaction
108: {
109: $this->description = $description;
110: $this->json->put( 'description', $description );
111: return $this;
112: }
113:
114: // COMMON
115:
116: function __construct( Json $json = null )
117: {
118: parent::__construct( $json );
119: }
120:
121: function addProof( PrivateKey $privateKey, int $index = null ): CurrentTransaction
122: {
123: $proof = (new \deemru\WavesKit)->sign( $this->bodyBytes(), $privateKey->bytes() );
124: if( $proof === false )
125: throw new Exception( __FUNCTION__ . ' unexpected sign() error', ExceptionCode::UNEXPECTED );
126: $proof = Base58String::fromBytes( $proof )->encoded();
127:
128: $proofs = $this->proofs();
129: if( !isset( $index ) )
130: $proofs[] = $proof;
131: else
132: $proofs[$index] = $proof;
133: return $this->setProofs( $proofs );
134: }
135:
136: /**
137: * @return CurrentTransaction
138: */
139: function setType( int $type )
140: {
141: parent::setType( $type );
142: return $this;
143: }
144:
145: /**
146: * @return CurrentTransaction
147: */
148: function setSender( PublicKey $sender )
149: {
150: parent::setSender( $sender );
151: return $this;
152: }
153:
154: /**
155: * @return CurrentTransaction
156: */
157: function setVersion( int $version )
158: {
159: parent::setVersion( $version );
160: return $this;
161: }
162:
163: /**
164: * @return CurrentTransaction
165: */
166: function setFee( Amount $fee )
167: {
168: parent::setFee( $fee );
169: return $this;
170: }
171:
172: /**
173: * @return CurrentTransaction
174: */
175: function setChainId( ChainId $chainId = null )
176: {
177: parent::setChainId( $chainId );
178: return $this;
179: }
180:
181: /**
182: * @return CurrentTransaction
183: */
184: function setTimestamp( int $timestamp = null )
185: {
186: parent::setTimestamp( $timestamp );
187: return $this;
188: }
189:
190: /**
191: * @param array<int, string> $proofs
192: * @return CurrentTransaction
193: */
194: function setProofs( array $proofs = null )
195: {
196: parent::setProofs( $proofs );
197: return $this;
198: }
199:
200: function bodyBytes(): string
201: {
202: if( !isset( $this->bodyBytes ) )
203: $this->getUnsigned();
204: return parent::bodyBytes();
205: }
206: }
207: