hive-stream 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/builders.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HiveVoteBuilder = exports.HiveRemoveProposalsBuilder = exports.HiveProposalVotesBuilder = exports.HiveEngineTokenIssueBuilder = exports.HiveEngineTokenBurnBuilder = exports.HiveEngineTokenTransferBuilder = exports.HiveProposalBuilder = exports.HiveRecurrentTransferBuilder = exports.HiveEscrowTransferBuilder = exports.HiveBurnBuilder = exports.HiveTransferBuilder = exports.IncomingTransfersBuilder = void 0;
3
+ exports.HiveCommunityOperationBuilder = exports.HiveEngineDelegateBuilder = exports.HiveEngineCancelOrderBuilder = exports.HiveEngineMarketOrderBuilder = exports.HiveEngineUnstakeBuilder = exports.HiveEngineStakeBuilder = exports.HiveBatchBuilder = exports.HivePostBuilder = exports.HiveCommentOptionsBuilder = exports.HiveWithdrawRouteBuilder = exports.HiveCancelOrderBuilder = exports.HiveLimitOrderBuilder = exports.HiveDeleteCommentBuilder = exports.HiveCollateralizedConvertBuilder = exports.HiveConvertBuilder = exports.HiveSavingsTransferBuilder = exports.HiveUpdateProfileBuilder = exports.HiveSetProxyBuilder = exports.HiveWitnessVoteBuilder = exports.HiveClaimRewardsBuilder = exports.HiveDelegateBuilder = exports.HivePowerDownBuilder = exports.HivePowerUpBuilder = exports.HiveReblogBuilder = exports.HiveFollowBuilder = exports.HiveVoteBuilder = exports.HiveRemoveProposalsBuilder = exports.HiveProposalVotesBuilder = exports.HiveEngineTokenIssueBuilder = exports.HiveEngineTokenBurnBuilder = exports.HiveEngineTokenTransferBuilder = exports.HiveProposalBuilder = exports.HiveRecurrentTransferBuilder = exports.HiveEscrowTransferBuilder = exports.HiveBurnBuilder = exports.HiveTransferBuilder = exports.IncomingTransfersBuilder = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  function normalizeAllocationInput(input, context) {
6
6
  if (typeof input === 'number') {
@@ -724,4 +724,886 @@ class HiveVoteBuilder {
724
724
  }
725
725
  }
726
726
  exports.HiveVoteBuilder = HiveVoteBuilder;
727
+ class HiveFollowBuilder {
728
+ streamer;
729
+ mode;
730
+ state = {};
731
+ constructor(streamer, mode) {
732
+ this.streamer = streamer;
733
+ this.mode = mode;
734
+ }
735
+ follower(account) {
736
+ this.state.follower = account;
737
+ return this;
738
+ }
739
+ following(account) {
740
+ this.state.following = account;
741
+ return this;
742
+ }
743
+ send() {
744
+ if (!this.state.follower || !this.state.following) {
745
+ throw new Error(`${this.mode}() builder requires follower and following before send()`);
746
+ }
747
+ if (this.mode === 'follow') {
748
+ return this.streamer.follow(this.state.follower, this.state.following);
749
+ }
750
+ if (this.mode === 'mute') {
751
+ return this.streamer.mute(this.state.follower, this.state.following);
752
+ }
753
+ return this.streamer.unfollow(this.state.follower, this.state.following);
754
+ }
755
+ }
756
+ exports.HiveFollowBuilder = HiveFollowBuilder;
757
+ class HiveReblogBuilder {
758
+ streamer;
759
+ state = {};
760
+ constructor(streamer) {
761
+ this.streamer = streamer;
762
+ }
763
+ account(account) {
764
+ this.state.account = account;
765
+ return this;
766
+ }
767
+ author(account) {
768
+ this.state.author = account;
769
+ return this;
770
+ }
771
+ permlink(value) {
772
+ this.state.permlink = value;
773
+ return this;
774
+ }
775
+ send() {
776
+ if (!this.state.account || !this.state.author || !this.state.permlink) {
777
+ throw new Error('reblog() builder requires account, author, and permlink before send()');
778
+ }
779
+ return this.streamer.reblog(this.state.account, this.state.author, this.state.permlink);
780
+ }
781
+ }
782
+ exports.HiveReblogBuilder = HiveReblogBuilder;
783
+ class HivePowerUpBuilder {
784
+ streamer;
785
+ state = {};
786
+ constructor(streamer) {
787
+ this.streamer = streamer;
788
+ }
789
+ from(account) {
790
+ this.state.from = account;
791
+ return this;
792
+ }
793
+ to(account) {
794
+ this.state.to = account;
795
+ return this;
796
+ }
797
+ amount(amount) {
798
+ this.state.amount = utils_1.Utils.formatAmount(amount);
799
+ return this;
800
+ }
801
+ send() {
802
+ if (!this.state.from || !this.state.amount) {
803
+ throw new Error('powerUp() builder requires from and amount before send()');
804
+ }
805
+ return this.streamer.powerUp(this.state.from, this.state.to || this.state.from, this.state.amount);
806
+ }
807
+ }
808
+ exports.HivePowerUpBuilder = HivePowerUpBuilder;
809
+ class HivePowerDownBuilder {
810
+ streamer;
811
+ cancel;
812
+ state = {};
813
+ constructor(streamer, cancel = false) {
814
+ this.streamer = streamer;
815
+ this.cancel = cancel;
816
+ }
817
+ account(account) {
818
+ this.state.account = account;
819
+ return this;
820
+ }
821
+ vestingShares(amount) {
822
+ this.state.vestingShares = amount;
823
+ return this;
824
+ }
825
+ send() {
826
+ if (!this.state.account) {
827
+ throw new Error('powerDown() builder requires account before send()');
828
+ }
829
+ if (this.cancel) {
830
+ return this.streamer.cancelPowerDown(this.state.account);
831
+ }
832
+ if (!this.state.vestingShares) {
833
+ throw new Error('powerDown() builder requires vestingShares before send()');
834
+ }
835
+ return this.streamer.powerDown(this.state.account, this.state.vestingShares);
836
+ }
837
+ }
838
+ exports.HivePowerDownBuilder = HivePowerDownBuilder;
839
+ class HiveDelegateBuilder {
840
+ streamer;
841
+ undelegate;
842
+ state = {};
843
+ constructor(streamer, undelegate = false) {
844
+ this.streamer = streamer;
845
+ this.undelegate = undelegate;
846
+ }
847
+ delegator(account) {
848
+ this.state.delegator = account;
849
+ return this;
850
+ }
851
+ delegatee(account) {
852
+ this.state.delegatee = account;
853
+ return this;
854
+ }
855
+ vestingShares(amount) {
856
+ this.state.vestingShares = amount;
857
+ return this;
858
+ }
859
+ send() {
860
+ if (!this.state.delegator || !this.state.delegatee) {
861
+ throw new Error('delegate() builder requires delegator and delegatee before send()');
862
+ }
863
+ if (this.undelegate) {
864
+ return this.streamer.undelegateVestingShares(this.state.delegator, this.state.delegatee);
865
+ }
866
+ if (!this.state.vestingShares) {
867
+ throw new Error('delegate() builder requires vestingShares before send()');
868
+ }
869
+ return this.streamer.delegateVestingShares(this.state.delegator, this.state.delegatee, this.state.vestingShares);
870
+ }
871
+ }
872
+ exports.HiveDelegateBuilder = HiveDelegateBuilder;
873
+ class HiveClaimRewardsBuilder {
874
+ streamer;
875
+ state = {};
876
+ constructor(streamer) {
877
+ this.streamer = streamer;
878
+ }
879
+ account(account) {
880
+ this.state.account = account;
881
+ return this;
882
+ }
883
+ rewardHive(amount) {
884
+ this.state.rewardHive = amount;
885
+ return this;
886
+ }
887
+ rewardHbd(amount) {
888
+ this.state.rewardHbd = amount;
889
+ return this;
890
+ }
891
+ rewardVests(amount) {
892
+ this.state.rewardVests = amount;
893
+ return this;
894
+ }
895
+ send() {
896
+ if (!this.state.account) {
897
+ throw new Error('claimRewards() builder requires account before send()');
898
+ }
899
+ return this.streamer.claimRewards(this.state.account, this.state.rewardHive || '0.000 HIVE', this.state.rewardHbd || '0.000 HBD', this.state.rewardVests || '0.000000 VESTS');
900
+ }
901
+ }
902
+ exports.HiveClaimRewardsBuilder = HiveClaimRewardsBuilder;
903
+ class HiveWitnessVoteBuilder {
904
+ streamer;
905
+ state = {};
906
+ constructor(streamer) {
907
+ this.streamer = streamer;
908
+ }
909
+ account(account) {
910
+ this.state.account = account;
911
+ return this;
912
+ }
913
+ witness(account) {
914
+ this.state.witness = account;
915
+ return this;
916
+ }
917
+ approve(value = true) {
918
+ this.state.approve = value;
919
+ return this;
920
+ }
921
+ unapprove() {
922
+ return this.approve(false);
923
+ }
924
+ send() {
925
+ if (!this.state.account || !this.state.witness) {
926
+ throw new Error('witnessVote() builder requires account and witness before send()');
927
+ }
928
+ return this.streamer.witnessVote(this.state.account, this.state.witness, this.state.approve !== false);
929
+ }
930
+ }
931
+ exports.HiveWitnessVoteBuilder = HiveWitnessVoteBuilder;
932
+ class HiveSetProxyBuilder {
933
+ streamer;
934
+ clear;
935
+ state = {};
936
+ constructor(streamer, clear = false) {
937
+ this.streamer = streamer;
938
+ this.clear = clear;
939
+ }
940
+ account(account) {
941
+ this.state.account = account;
942
+ return this;
943
+ }
944
+ proxy(account) {
945
+ this.state.proxy = account;
946
+ return this;
947
+ }
948
+ send() {
949
+ if (!this.state.account) {
950
+ throw new Error('setProxy() builder requires account before send()');
951
+ }
952
+ if (this.clear) {
953
+ return this.streamer.clearProxy(this.state.account);
954
+ }
955
+ if (!this.state.proxy) {
956
+ throw new Error('setProxy() builder requires proxy before send()');
957
+ }
958
+ return this.streamer.setProxy(this.state.account, this.state.proxy);
959
+ }
960
+ }
961
+ exports.HiveSetProxyBuilder = HiveSetProxyBuilder;
962
+ class HiveUpdateProfileBuilder {
963
+ streamer;
964
+ state = { profile: {} };
965
+ constructor(streamer) {
966
+ this.streamer = streamer;
967
+ }
968
+ account(account) {
969
+ this.state.account = account;
970
+ return this;
971
+ }
972
+ name(value) {
973
+ this.state.profile.name = value;
974
+ return this;
975
+ }
976
+ about(value) {
977
+ this.state.profile.about = value;
978
+ return this;
979
+ }
980
+ location(value) {
981
+ this.state.profile.location = value;
982
+ return this;
983
+ }
984
+ website(value) {
985
+ this.state.profile.website = value;
986
+ return this;
987
+ }
988
+ profileImage(url) {
989
+ this.state.profile.profile_image = url;
990
+ return this;
991
+ }
992
+ coverImage(url) {
993
+ this.state.profile.cover_image = url;
994
+ return this;
995
+ }
996
+ set(key, value) {
997
+ this.state.profile[key] = value;
998
+ return this;
999
+ }
1000
+ send() {
1001
+ if (!this.state.account) {
1002
+ throw new Error('updateProfile() builder requires account before send()');
1003
+ }
1004
+ if (Object.keys(this.state.profile).length === 0) {
1005
+ throw new Error('updateProfile() builder requires at least one profile field before send()');
1006
+ }
1007
+ return this.streamer.updateProfile(this.state.account, this.state.profile);
1008
+ }
1009
+ }
1010
+ exports.HiveUpdateProfileBuilder = HiveUpdateProfileBuilder;
1011
+ class HiveSavingsTransferBuilder {
1012
+ streamer;
1013
+ direction;
1014
+ state = {};
1015
+ constructor(streamer, direction) {
1016
+ this.streamer = streamer;
1017
+ this.direction = direction;
1018
+ }
1019
+ from(account) {
1020
+ this.state.from = account;
1021
+ return this;
1022
+ }
1023
+ to(account) {
1024
+ this.state.to = account;
1025
+ return this;
1026
+ }
1027
+ amount(amount, symbol) {
1028
+ const parsed = parseAssetInput(amount, symbol);
1029
+ this.state.amount = parsed.amount;
1030
+ this.state.symbol = parsed.symbol;
1031
+ return this;
1032
+ }
1033
+ hive(amount) {
1034
+ return this.amount(amount, 'HIVE');
1035
+ }
1036
+ hbd(amount) {
1037
+ return this.amount(amount, 'HBD');
1038
+ }
1039
+ memo(memo) {
1040
+ this.state.memo = memo;
1041
+ return this;
1042
+ }
1043
+ requestId(id) {
1044
+ this.state.requestId = id;
1045
+ return this;
1046
+ }
1047
+ send() {
1048
+ if (!this.state.from || !this.state.amount || !this.state.symbol) {
1049
+ throw new Error(`${this.direction === 'to' ? 'transferToSavings' : 'transferFromSavings'}() builder requires from and amount before send()`);
1050
+ }
1051
+ const to = this.state.to || this.state.from;
1052
+ if (this.direction === 'to') {
1053
+ return this.streamer.transferToSavings(this.state.from, to, this.state.amount, this.state.symbol, this.state.memo || '');
1054
+ }
1055
+ return this.streamer.transferFromSavings(this.state.from, to, this.state.amount, this.state.symbol, this.state.requestId || 0, this.state.memo || '');
1056
+ }
1057
+ }
1058
+ exports.HiveSavingsTransferBuilder = HiveSavingsTransferBuilder;
1059
+ class HiveConvertBuilder {
1060
+ streamer;
1061
+ state = {};
1062
+ constructor(streamer) {
1063
+ this.streamer = streamer;
1064
+ }
1065
+ from(account) {
1066
+ this.state.from = account;
1067
+ return this;
1068
+ }
1069
+ amount(amount, symbol) {
1070
+ this.state.amount = buildAssetAmount(amount, symbol || 'HBD');
1071
+ return this;
1072
+ }
1073
+ hbd(amount) {
1074
+ return this.amount(amount, 'HBD');
1075
+ }
1076
+ requestId(id) {
1077
+ this.state.requestId = id;
1078
+ return this;
1079
+ }
1080
+ send() {
1081
+ if (!this.state.from || !this.state.amount) {
1082
+ throw new Error('convert() builder requires from and amount before send()');
1083
+ }
1084
+ return this.streamer.convert(this.state.from, this.state.amount, this.state.requestId || 0);
1085
+ }
1086
+ }
1087
+ exports.HiveConvertBuilder = HiveConvertBuilder;
1088
+ class HiveCollateralizedConvertBuilder {
1089
+ streamer;
1090
+ state = {};
1091
+ constructor(streamer) {
1092
+ this.streamer = streamer;
1093
+ }
1094
+ from(account) {
1095
+ this.state.from = account;
1096
+ return this;
1097
+ }
1098
+ amount(amount, symbol) {
1099
+ this.state.amount = buildAssetAmount(amount, symbol || 'HIVE');
1100
+ return this;
1101
+ }
1102
+ hive(amount) {
1103
+ return this.amount(amount, 'HIVE');
1104
+ }
1105
+ requestId(id) {
1106
+ this.state.requestId = id;
1107
+ return this;
1108
+ }
1109
+ send() {
1110
+ if (!this.state.from || !this.state.amount) {
1111
+ throw new Error('collateralizedConvert() builder requires from and amount before send()');
1112
+ }
1113
+ return this.streamer.collateralizedConvert(this.state.from, this.state.amount, this.state.requestId || 0);
1114
+ }
1115
+ }
1116
+ exports.HiveCollateralizedConvertBuilder = HiveCollateralizedConvertBuilder;
1117
+ class HiveDeleteCommentBuilder {
1118
+ streamer;
1119
+ state = {};
1120
+ constructor(streamer) {
1121
+ this.streamer = streamer;
1122
+ }
1123
+ author(account) {
1124
+ this.state.author = account;
1125
+ return this;
1126
+ }
1127
+ permlink(value) {
1128
+ this.state.permlink = value;
1129
+ return this;
1130
+ }
1131
+ send() {
1132
+ if (!this.state.author || !this.state.permlink) {
1133
+ throw new Error('deleteComment() builder requires author and permlink before send()');
1134
+ }
1135
+ return this.streamer.deleteComment(this.state.author, this.state.permlink);
1136
+ }
1137
+ }
1138
+ exports.HiveDeleteCommentBuilder = HiveDeleteCommentBuilder;
1139
+ class HiveLimitOrderBuilder {
1140
+ streamer;
1141
+ state = {};
1142
+ constructor(streamer) {
1143
+ this.streamer = streamer;
1144
+ }
1145
+ owner(account) {
1146
+ this.state.owner = account;
1147
+ return this;
1148
+ }
1149
+ orderId(id) {
1150
+ this.state.orderId = id;
1151
+ return this;
1152
+ }
1153
+ amountToSell(amount, symbol) {
1154
+ this.state.amountToSell = buildAssetAmount(amount, symbol);
1155
+ return this;
1156
+ }
1157
+ minToReceive(amount, symbol) {
1158
+ this.state.minToReceive = buildAssetAmount(amount, symbol);
1159
+ return this;
1160
+ }
1161
+ fillOrKill(value = true) {
1162
+ this.state.fillOrKill = value;
1163
+ return this;
1164
+ }
1165
+ expiration(value) {
1166
+ this.state.expiration = value;
1167
+ return this;
1168
+ }
1169
+ send(signingKeys) {
1170
+ if (!this.state.owner || !this.state.amountToSell || !this.state.minToReceive) {
1171
+ throw new Error('limitOrder() builder requires owner, amountToSell, and minToReceive before send()');
1172
+ }
1173
+ return this.streamer.limitOrderCreate(this.state.owner, this.state.orderId || Math.floor(Date.now() / 1000), this.state.amountToSell, this.state.minToReceive, this.state.fillOrKill || false, this.state.expiration, signingKeys);
1174
+ }
1175
+ }
1176
+ exports.HiveLimitOrderBuilder = HiveLimitOrderBuilder;
1177
+ class HiveCancelOrderBuilder {
1178
+ streamer;
1179
+ state = {};
1180
+ constructor(streamer) {
1181
+ this.streamer = streamer;
1182
+ }
1183
+ owner(account) {
1184
+ this.state.owner = account;
1185
+ return this;
1186
+ }
1187
+ orderId(id) {
1188
+ this.state.orderId = id;
1189
+ return this;
1190
+ }
1191
+ send(signingKeys) {
1192
+ if (!this.state.owner || this.state.orderId === undefined) {
1193
+ throw new Error('cancelOrder() builder requires owner and orderId before send()');
1194
+ }
1195
+ return this.streamer.limitOrderCancel(this.state.owner, this.state.orderId, signingKeys);
1196
+ }
1197
+ }
1198
+ exports.HiveCancelOrderBuilder = HiveCancelOrderBuilder;
1199
+ class HiveWithdrawRouteBuilder {
1200
+ streamer;
1201
+ state = {};
1202
+ constructor(streamer) {
1203
+ this.streamer = streamer;
1204
+ }
1205
+ from(account) {
1206
+ this.state.from = account;
1207
+ return this;
1208
+ }
1209
+ to(account) {
1210
+ this.state.to = account;
1211
+ return this;
1212
+ }
1213
+ percent(value) {
1214
+ this.state.percent = value;
1215
+ return this;
1216
+ }
1217
+ autoVest(value = true) {
1218
+ this.state.autoVest = value;
1219
+ return this;
1220
+ }
1221
+ send(signingKeys) {
1222
+ if (!this.state.from || !this.state.to || this.state.percent === undefined) {
1223
+ throw new Error('withdrawRoute() builder requires from, to, and percent before send()');
1224
+ }
1225
+ return this.streamer.setWithdrawVestingRoute(this.state.from, this.state.to, this.state.percent, this.state.autoVest || false, signingKeys);
1226
+ }
1227
+ }
1228
+ exports.HiveWithdrawRouteBuilder = HiveWithdrawRouteBuilder;
1229
+ class HiveCommentOptionsBuilder {
1230
+ streamer;
1231
+ state = { beneficiaries: [] };
1232
+ constructor(streamer) {
1233
+ this.streamer = streamer;
1234
+ }
1235
+ author(account) {
1236
+ this.state.author = account;
1237
+ return this;
1238
+ }
1239
+ permlink(value) {
1240
+ this.state.permlink = value;
1241
+ return this;
1242
+ }
1243
+ maxAcceptedPayout(amount, symbol) {
1244
+ this.state.maxAcceptedPayout = buildAssetAmount(amount, symbol || 'HBD');
1245
+ return this;
1246
+ }
1247
+ percentHbd(value) {
1248
+ this.state.percentHbd = value;
1249
+ return this;
1250
+ }
1251
+ allowVotes(value = true) {
1252
+ this.state.allowVotes = value;
1253
+ return this;
1254
+ }
1255
+ allowCurationRewards(value = true) {
1256
+ this.state.allowCurationRewards = value;
1257
+ return this;
1258
+ }
1259
+ beneficiary(account, weight) {
1260
+ this.state.beneficiaries.push({ account, weight });
1261
+ return this;
1262
+ }
1263
+ send() {
1264
+ if (!this.state.author || !this.state.permlink) {
1265
+ throw new Error('commentOptions() builder requires author and permlink before send()');
1266
+ }
1267
+ const extensions = [];
1268
+ if (this.state.beneficiaries.length > 0) {
1269
+ extensions.push([0, { beneficiaries: this.state.beneficiaries }]);
1270
+ }
1271
+ return this.streamer.commentOptions(this.state.author, this.state.permlink, {
1272
+ max_accepted_payout: this.state.maxAcceptedPayout,
1273
+ percent_hbd: this.state.percentHbd,
1274
+ allow_votes: this.state.allowVotes,
1275
+ allow_curation_rewards: this.state.allowCurationRewards,
1276
+ extensions
1277
+ });
1278
+ }
1279
+ }
1280
+ exports.HiveCommentOptionsBuilder = HiveCommentOptionsBuilder;
1281
+ class HivePostBuilder {
1282
+ streamer;
1283
+ state = {
1284
+ tags: [],
1285
+ parentAuthor: '',
1286
+ parentPermlink: '',
1287
+ beneficiaries: [],
1288
+ appName: 'hive-stream',
1289
+ formatType: 'markdown',
1290
+ images: [],
1291
+ extraMetadata: {}
1292
+ };
1293
+ constructor(streamer) {
1294
+ this.streamer = streamer;
1295
+ }
1296
+ author(account) {
1297
+ this.state.author = account;
1298
+ return this;
1299
+ }
1300
+ title(value) {
1301
+ this.state.title = value;
1302
+ return this;
1303
+ }
1304
+ body(value) {
1305
+ this.state.body = value;
1306
+ return this;
1307
+ }
1308
+ permlink(value) {
1309
+ this.state.permlink = value;
1310
+ return this;
1311
+ }
1312
+ tags(...tags) {
1313
+ this.state.tags = tags.map(t => t.trim().toLowerCase()).filter(Boolean);
1314
+ return this;
1315
+ }
1316
+ community(name) {
1317
+ this.state.communityName = name;
1318
+ return this;
1319
+ }
1320
+ parentAuthor(account) {
1321
+ this.state.parentAuthor = account;
1322
+ return this;
1323
+ }
1324
+ parentPermlink(value) {
1325
+ this.state.parentPermlink = value;
1326
+ return this;
1327
+ }
1328
+ beneficiary(account, weight) {
1329
+ this.state.beneficiaries.push({ account, weight });
1330
+ return this;
1331
+ }
1332
+ maxAcceptedPayout(amount, symbol) {
1333
+ this.state.maxAcceptedPayout = buildAssetAmount(amount, symbol || 'HBD');
1334
+ return this;
1335
+ }
1336
+ percentHbd(value) {
1337
+ this.state.percentHbd = value;
1338
+ return this;
1339
+ }
1340
+ allowVotes(value = true) {
1341
+ this.state.allowVotes = value;
1342
+ return this;
1343
+ }
1344
+ allowCurationRewards(value = true) {
1345
+ this.state.allowCurationRewards = value;
1346
+ return this;
1347
+ }
1348
+ app(name) {
1349
+ this.state.appName = name;
1350
+ return this;
1351
+ }
1352
+ format(value) {
1353
+ this.state.formatType = value;
1354
+ return this;
1355
+ }
1356
+ description(value) {
1357
+ this.state.descriptionText = value;
1358
+ return this;
1359
+ }
1360
+ image(...urls) {
1361
+ this.state.images.push(...urls);
1362
+ return this;
1363
+ }
1364
+ metadata(key, value) {
1365
+ this.state.extraMetadata[key] = value;
1366
+ return this;
1367
+ }
1368
+ send() {
1369
+ if (!this.state.author) {
1370
+ throw new Error('post() builder requires author before send()');
1371
+ }
1372
+ if (!this.state.body) {
1373
+ throw new Error('post() builder requires body before send()');
1374
+ }
1375
+ const isReply = !!this.state.parentAuthor;
1376
+ // Generate permlink if not provided
1377
+ const permlink = this.state.permlink
1378
+ || (isReply
1379
+ ? utils_1.Utils.generateReplyPermlink(this.state.parentPermlink)
1380
+ : utils_1.Utils.generatePermlink(this.state.title || 'untitled'));
1381
+ // Determine parent_permlink for top-level posts
1382
+ let parentPermlink = this.state.parentPermlink;
1383
+ if (!isReply) {
1384
+ if (this.state.communityName) {
1385
+ parentPermlink = this.state.communityName;
1386
+ }
1387
+ else if (this.state.tags.length > 0) {
1388
+ parentPermlink = this.state.tags[0];
1389
+ }
1390
+ else {
1391
+ parentPermlink = 'hive-stream';
1392
+ }
1393
+ }
1394
+ // Build json_metadata
1395
+ const jsonMetadata = utils_1.Utils.createPostMetadata({
1396
+ tags: this.state.tags,
1397
+ image: this.state.images.length > 0 ? this.state.images : utils_1.Utils.extractImagesFromBody(this.state.body),
1398
+ app: this.state.appName,
1399
+ format: this.state.formatType,
1400
+ description: this.state.descriptionText,
1401
+ ...this.state.extraMetadata
1402
+ });
1403
+ // Build the comment operation
1404
+ const commentOp = ['comment', {
1405
+ parent_author: this.state.parentAuthor,
1406
+ parent_permlink: parentPermlink,
1407
+ author: this.state.author,
1408
+ permlink,
1409
+ title: this.state.title || '',
1410
+ body: this.state.body,
1411
+ json_metadata: jsonMetadata
1412
+ }];
1413
+ // Check if we need comment_options
1414
+ const needsOptions = this.state.beneficiaries.length > 0
1415
+ || this.state.maxAcceptedPayout !== undefined
1416
+ || this.state.percentHbd !== undefined
1417
+ || this.state.allowVotes !== undefined
1418
+ || this.state.allowCurationRewards !== undefined;
1419
+ if (!needsOptions) {
1420
+ return this.streamer.broadcastOperations([commentOp]);
1421
+ }
1422
+ // Build comment_options operation
1423
+ const extensions = [];
1424
+ if (this.state.beneficiaries.length > 0) {
1425
+ const sorted = [...this.state.beneficiaries].sort((a, b) => a.account.localeCompare(b.account));
1426
+ extensions.push([0, { beneficiaries: sorted }]);
1427
+ }
1428
+ const commentOptionsOp = ['comment_options', {
1429
+ author: this.state.author,
1430
+ permlink,
1431
+ max_accepted_payout: this.state.maxAcceptedPayout || '1000000.000 HBD',
1432
+ percent_hbd: this.state.percentHbd !== undefined ? this.state.percentHbd : 10000,
1433
+ allow_votes: this.state.allowVotes !== false,
1434
+ allow_curation_rewards: this.state.allowCurationRewards !== false,
1435
+ extensions
1436
+ }];
1437
+ // Broadcast both atomically
1438
+ return this.streamer.broadcastOperations([commentOp, commentOptionsOp]);
1439
+ }
1440
+ }
1441
+ exports.HivePostBuilder = HivePostBuilder;
1442
+ class HiveBatchBuilder {
1443
+ streamer;
1444
+ operations = [];
1445
+ constructor(streamer) {
1446
+ this.streamer = streamer;
1447
+ }
1448
+ add(operation) {
1449
+ this.operations.push(operation);
1450
+ return this;
1451
+ }
1452
+ transfer(from, to, amount, memo = '') {
1453
+ this.operations.push(['transfer', { from, to, amount, memo }]);
1454
+ return this;
1455
+ }
1456
+ vote(voter, author, permlink, weight) {
1457
+ this.operations.push(['vote', { voter, author, permlink, weight }]);
1458
+ return this;
1459
+ }
1460
+ customJson(id, json, postingAuth, activeAuth) {
1461
+ const jsonStr = typeof json === 'string' ? json : JSON.stringify(json);
1462
+ this.operations.push(['custom_json', {
1463
+ required_auths: activeAuth ? [activeAuth] : [],
1464
+ required_posting_auths: postingAuth ? [postingAuth] : [],
1465
+ id,
1466
+ json: jsonStr
1467
+ }]);
1468
+ return this;
1469
+ }
1470
+ comment(author, permlink, parentAuthor, parentPermlink, title, body, jsonMetadata = '{}') {
1471
+ this.operations.push(['comment', {
1472
+ parent_author: parentAuthor,
1473
+ parent_permlink: parentPermlink,
1474
+ author,
1475
+ permlink,
1476
+ title,
1477
+ body,
1478
+ json_metadata: jsonMetadata
1479
+ }]);
1480
+ return this;
1481
+ }
1482
+ send(signingKeys) {
1483
+ if (this.operations.length === 0) {
1484
+ throw new Error('batch() builder requires at least one operation before send()');
1485
+ }
1486
+ return this.streamer.broadcastOperations(this.operations, signingKeys);
1487
+ }
1488
+ }
1489
+ exports.HiveBatchBuilder = HiveBatchBuilder;
1490
+ class HiveEngineStakeBuilder {
1491
+ streamer;
1492
+ state = {};
1493
+ constructor(streamer) {
1494
+ this.streamer = streamer;
1495
+ }
1496
+ from(account) { this.state.from = account; return this; }
1497
+ to(account) { this.state.to = account; return this; }
1498
+ symbol(symbol) { this.state.symbol = symbol; return this; }
1499
+ quantity(quantity) { this.state.quantity = String(quantity); return this; }
1500
+ send() {
1501
+ if (!this.state.from || !this.state.symbol || !this.state.quantity) {
1502
+ throw new Error('stakeEngine() builder requires from, symbol, and quantity before send()');
1503
+ }
1504
+ return this.streamer.stakeEngineTokens(this.state.from, this.state.to || this.state.from, this.state.symbol, this.state.quantity);
1505
+ }
1506
+ }
1507
+ exports.HiveEngineStakeBuilder = HiveEngineStakeBuilder;
1508
+ class HiveEngineUnstakeBuilder {
1509
+ streamer;
1510
+ state = {};
1511
+ constructor(streamer) {
1512
+ this.streamer = streamer;
1513
+ }
1514
+ from(account) { this.state.from = account; return this; }
1515
+ symbol(symbol) { this.state.symbol = symbol; return this; }
1516
+ quantity(quantity) { this.state.quantity = String(quantity); return this; }
1517
+ send() {
1518
+ if (!this.state.from || !this.state.symbol || !this.state.quantity) {
1519
+ throw new Error('unstakeEngine() builder requires from, symbol, and quantity before send()');
1520
+ }
1521
+ return this.streamer.unstakeEngineTokens(this.state.from, this.state.symbol, this.state.quantity);
1522
+ }
1523
+ }
1524
+ exports.HiveEngineUnstakeBuilder = HiveEngineUnstakeBuilder;
1525
+ class HiveEngineMarketOrderBuilder {
1526
+ streamer;
1527
+ side;
1528
+ state = {};
1529
+ constructor(streamer, side) {
1530
+ this.streamer = streamer;
1531
+ this.side = side;
1532
+ }
1533
+ from(account) { this.state.from = account; return this; }
1534
+ symbol(symbol) { this.state.symbol = symbol; return this; }
1535
+ quantity(quantity) { this.state.quantity = String(quantity); return this; }
1536
+ price(price) { this.state.price = String(price); return this; }
1537
+ send() {
1538
+ if (!this.state.from || !this.state.symbol || !this.state.quantity || !this.state.price) {
1539
+ throw new Error(`${this.side}Engine() builder requires from, symbol, quantity, and price before send()`);
1540
+ }
1541
+ if (this.side === 'buy') {
1542
+ return this.streamer.buyEngineTokens(this.state.from, this.state.symbol, this.state.quantity, this.state.price);
1543
+ }
1544
+ return this.streamer.sellEngineTokens(this.state.from, this.state.symbol, this.state.quantity, this.state.price);
1545
+ }
1546
+ }
1547
+ exports.HiveEngineMarketOrderBuilder = HiveEngineMarketOrderBuilder;
1548
+ class HiveEngineCancelOrderBuilder {
1549
+ streamer;
1550
+ state = {};
1551
+ constructor(streamer) {
1552
+ this.streamer = streamer;
1553
+ }
1554
+ from(account) { this.state.from = account; return this; }
1555
+ type(type) { this.state.type = type; return this; }
1556
+ orderId(id) { this.state.orderId = id; return this; }
1557
+ send() {
1558
+ if (!this.state.from || !this.state.type || !this.state.orderId) {
1559
+ throw new Error('cancelEngineOrder() builder requires from, type, and orderId before send()');
1560
+ }
1561
+ return this.streamer.cancelEngineOrder(this.state.from, this.state.type, this.state.orderId);
1562
+ }
1563
+ }
1564
+ exports.HiveEngineCancelOrderBuilder = HiveEngineCancelOrderBuilder;
1565
+ class HiveEngineDelegateBuilder {
1566
+ streamer;
1567
+ undelegate;
1568
+ state = {};
1569
+ constructor(streamer, undelegate = false) {
1570
+ this.streamer = streamer;
1571
+ this.undelegate = undelegate;
1572
+ }
1573
+ from(account) { this.state.from = account; return this; }
1574
+ to(account) { this.state.to = account; return this; }
1575
+ symbol(symbol) { this.state.symbol = symbol; return this; }
1576
+ quantity(quantity) { this.state.quantity = String(quantity); return this; }
1577
+ send() {
1578
+ if (!this.state.from || !this.state.to || !this.state.symbol || !this.state.quantity) {
1579
+ throw new Error(`${this.undelegate ? 'undelegateEngine' : 'delegateEngine'}() builder requires from, to, symbol, and quantity before send()`);
1580
+ }
1581
+ if (this.undelegate) {
1582
+ return this.streamer.undelegateEngineTokens(this.state.from, this.state.to, this.state.symbol, this.state.quantity);
1583
+ }
1584
+ return this.streamer.delegateEngineTokens(this.state.from, this.state.to, this.state.symbol, this.state.quantity);
1585
+ }
1586
+ }
1587
+ exports.HiveEngineDelegateBuilder = HiveEngineDelegateBuilder;
1588
+ class HiveCommunityOperationBuilder {
1589
+ streamer;
1590
+ action;
1591
+ state = {};
1592
+ constructor(streamer, action) {
1593
+ this.streamer = streamer;
1594
+ this.action = action;
1595
+ }
1596
+ account(account) { this.state.account = account; return this; }
1597
+ community(name) { this.state.community = name; return this; }
1598
+ send() {
1599
+ if (!this.state.account || !this.state.community) {
1600
+ throw new Error(`${this.action}Community() builder requires account and community before send()`);
1601
+ }
1602
+ if (this.action === 'subscribe') {
1603
+ return this.streamer.subscribeCommunity(this.state.account, this.state.community);
1604
+ }
1605
+ return this.streamer.unsubscribeCommunity(this.state.account, this.state.community);
1606
+ }
1607
+ }
1608
+ exports.HiveCommunityOperationBuilder = HiveCommunityOperationBuilder;
727
1609
  //# sourceMappingURL=builders.js.map